Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 343CF6501C2 for ; Wed, 30 Jul 2008 15:44:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 02335-03 for ; Wed, 30 Jul 2008 15:44:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail25.svc.cra.dublin.eircom.net (mail25.svc.cra.dublin.eircom.net [159.134.118.54]) by postgresql.org (Postfix) with SMTP id C1EDC6501AD for ; Wed, 30 Jul 2008 15:44:12 -0300 (ADT) Received: (qmail 33319 messnum 16401579 invoked from network[86.43.79.16/unknown]); 30 Jul 2008 18:44:08 -0000 Received: from unknown (HELO ?127.0.0.1?) (86.43.79.16) by mail25.svc.cra.dublin.eircom.net (qp 33319) with SMTP; 30 Jul 2008 18:44:08 -0000 Message-ID: <4890B679.9010301@iol.ie> Date: Wed, 30 Jul 2008 19:44:09 +0100 From: Raymond O'Donnell Reply-To: rod@iol.ie User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: PJ CC: Matthias Ritzkowski , pgsql-php@postgresql.org Subject: Re: display query results References: <48909454.7040305@videotron.ca> <4890A983.2040005@videotron.ca> In-Reply-To: <4890A983.2040005@videotron.ca> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 080730-0, 30/07/2008), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/7 X-Sequence-Number: 3871 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 ------------------------------------------------------------------