I noticed that many people use FOR loops to extract query data. This is the method I use to extract data.
<?php
@$members = pg_query($db_conn, 'SELECT id,name FROM boards.members ORDER BY name;');
if ($members AND pg_num_rows($members)) {
while ($member = pg_fetch_object($members)) {
echo $member->name.' ('.$member->id.')';
}
}
?>
If an error occurs (or nothing is returned) in the above code nothing will output. An ELSE clause can be added to the IF to handle query errors (or nothing being returned). Or a seperate check can be performed for the event that nothing is returned by using an ELSEIF clause.
I like this method because it doesn't use any temporary counter variables.