Link to home
Start Free TrialLog in
Avatar of R7AF
R7AFFlag for Netherlands

asked on

No results for php/postgresql query

When I execute the following code, I get a blank page. However, if I remove the complete for-loop, and only display the number of rows (pg_num_rows($result)), I do get the correct value back. I don't see what I'm doing wrong here.

System: Windows Vista, PG8.3, PHP 5.2.9
<?php
$query = "select name from person;";
$result = pg_query($db, $query);
if ($result)
{
	$rows = pg_num_rows($result);
	echo("result: ". $rows);
	// start problem code
	for ($row = 0; $row < $rows; $row++)
	{
		$values = pg_fetch_row($result, $row);
		echo 'Person: ' . implode(' ', $values) . " <br/>\n";
	}
	else
	{
		echo ("Query error: " . pg_last_error($db) );
	} 
	// end problem code
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R7AF

ASKER

Thank you! Two excellent tips, the second probably even more valuable.