Re: display query results
От | Raymond O'Donnell |
---|---|
Тема | Re: display query results |
Дата | |
Msg-id | 4890B679.9010301@iol.ie обсуждение исходный текст |
Ответ на | Re: display query results (PJ <af.gourmet@videotron.ca>) |
Список | pgsql-php |
On 30/07/2008 18:48, PJ wrote: > Doesn't work... and I feel totally lost. I don't understand the > pg_fetch_* stuff at all. Here's what you need to do: // Open a connection to the database. $conn = pg_connect($your_connection_string); // Execute a query which returns some rows. $result = pg_query($conn, 'select foo, bar from your_table'); // Loop through the rows one by one. // pg_fetch_array() returns the row as an array with a numeric index, // while pg_fetch_assoc() returns the row as an associative array // keyed on the column names. I usually use the latter. Both return // false when no more rows are available, so this is the usual idiom: while ($row = pg_fetch_assoc($result)) { print 'Some values: ' . $row['foo'] . ', ' . $row['bar'] . "\n"; } The other pg_fetch_* functions do various other things, such as (for example) fetching a value from a particular column in a particular row. HTH, Ray. ------------------------------------------------------------------ Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland rod@iol.ie Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals ------------------------------------------------------------------
В списке pgsql-php по дате отправления: