note 50342 added to function.pg-fetch-assoc

From: Date: Fri, 25 Feb 2005 03:22:48 +0000
Subject: note 50342 added to function.pg-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-85522@lists.php.net to get a copy of this message
$dbconn3 = pg_connect("host=127.0.0.1 port=5432 dbname=blah user=blah password=blah"); $result = pg_query($dbconn3, "SELECT * FROM Packages"); echo "<HTML><HEAD><TITLE>PostgreSQL Test Page</TITLE></HEAD><BODY>"; echo "<TABLE>"; $pkg = pg_fetch_assoc($result); foreach ($pkg as $value) { echo "<TR><TD>$value"; echo "</TR></TD>"; } echo "</TABLE><P>"; echo "This package's full filename is: {$pkg['name']}-{$pkg['version']}{$pkg['extension']}"; echo "</BODY></HTML>"; For generating tables, this works, and personally I prefer foreach() to while loops because there's no danger of accidentally causing an infinite loop...foreach only works for as long as it has something to work with, and then stops. I thought the echo down the bottom might come in handy, too...took me a bit to find that out. ---- Manual Page -- http://www.php.net/manual/en/function.pg-fetch-assoc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50342 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50342&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50342&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50342&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50342&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50342&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50342&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85522) next »