I am stuck with displaying result into table format. I tried with all options like "pg_fetch_row, pg_fetch_array, pg_fetch_all_columns", but I am not getting results in table format.
The query part is working fine, also I am getting results in XML format, but I need to display it in table format, also it should contain a column heading.
Please can anyone suggest me how to get the results in table format.
My PHP_PostgreSQL code shown in below:
<?
$conn = pg_connect("user=postgres password=nkr@123 host=localhost dbname=test");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
echo "Value of \$cat = $cat <br>Value of \$subcat = $subcat \n";
$result = pg_query($conn, "SELECT * FROM $cat JOIN $subcat ON $cat.districtco=$subcat.districtcode");
if (!$result) {
echo "An error occured in result.\n";
exit;
}
echo $result;
if (!$result) {
echo "An error occured in xml_result.\n";
exit;
}
?>
I am using this code to get results in XML:
$xml_result="<resultxml>";
$num = pg_num_fields($result);
while($row = pg_fetch_array($result)){
$xml_result.="<record>";
for ($i=0; $i < $num; $i++)
{
$xml_result .= "<".pg_field_name($result, $i).">".$row[$i]."</".pg_field_name($result, $i).">";
}
$xml_result.="</record>";
}
$xml_result.="</resultxml>";
echo $xml_result;