postgres php没有给出结果集中的每一列

postgres php没有给出结果集中的每一列,php,ajax,postgresql,pgadmin,Php,Ajax,Postgresql,Pgadmin,我有一个产品主表和其他各种包含产品属性的表,查询: select p.description, category.value, colour.value, wood.value, brand.value, type.value, fabric.value, model.value from product_master p, category, colour, wood, brand, type, fabric, model where p.category_code=category.cate

我有一个产品主表和其他各种包含产品属性的表,查询:

select p.description, category.value, colour.value, wood.value, brand.value, type.value, fabric.value, model.value from product_master p, category, colour, wood, brand, type, fabric, model where p.category_code=category.category_code and p.colour_code = colour.colour_code and p.wood_code = wood.wood_code and p.brand_code = brand.brand_code and p.type_code = type.type_code and p.fabric_code = fabric.fabric_code and p.model_code = model.model_code
在pgAdmin中运行良好,但在php中它只提供2列,我通过AJAX返回结果

我的php代码是

<?php
// Connecting, selecting database
$dbconn = pg_connect("host=***** dbname=*** user=*** password=***")
    or die('Could not connect: ' . pg_last_error());

// Performing SQL query
$query = ' select p.description, category.value, colour.value, wood.value, brand.value, type.value, fabric.value, model.value from product_master p, category, colour, wood, brand, type, fabric, model where p.category_code=category.category_code and p.colour_code = colour.colour_code and p.wood_code = wood.wood_code and p.brand_code = brand.brand_code and p.type_code = type.type_code and p.fabric_code = fabric.fabric_code and p.model_code = model.model_code ';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());



echo pg_affected_rows($result) ;

echo "\n";

echo pg_num_fields($result);


// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>

您使用不正确。不能将第二个参数作为NULL传递,因为它指示正在读取的行

试试这个:

while ($line = pg_fetch_array($result)) {
    echo "\t<tr>\n";

    foreach ($line as $col_value) 
        echo "\t\t<td>$col_value</td>\n";

    echo "\t</tr>\n";
}
while($line=pg\u fetch\u数组($result)){
回显“\t\n”;
foreach($列为$colu值)
回显“\t\t$col\u值\n”;
回显“\t\n”;
}

对于
select
子句,您应该使用它,而不是pg_infected_rows()@MarcioSimao同意您指出这一点,但不幸的是,这不是我的主要关注点。我已经写了一个答案,请看它是否对您有帮助