note 17642 added to function.pg-fetch-array
| From: | chris at kuri dot com | Date: | Tue, 18 Dec 2001 09:08:04 +0000 |
| Subject: | note 17642 added to function.pg-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-23117@lists.php.net to get a copy of this message | ||
The correct way to loop through the result is to use pg_numrows.
<html>
<head><title>postgres query</title></head>
<body>
<table border="1">
<?php
$connection = pg_connect("host=localhost dbname=mydb");
$result = pg_exec( $connection, "SELECT * FROM mydb");
for ( $i=0; $i < pg_numrows($result); $i++) {
$row = pg_fetch_array($result, $i, $PGSQL_ASSOC);
echo "<tr>";
foreach ( $row as $field ) {
echo ("<td>" . $field . "</td>");
}
echo "</tr>";
}
?>
</table>
</body>
</html>
--
http://www.php.net/manual/en/function.pg-fetch-array.php
http://master.php.net/manage/user-notes.php?action=edit+17642
http://master.php.net/manage/user-notes.php?action=delete+17642
http://master.php.net/manage/user-notes.php?action=reject+17642