Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E286F64FC85 for ; Fri, 2 Jan 2009 14:18:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 90811-07 for ; Fri, 2 Jan 2009 14:17:58 -0400 (AST) X-Greylist: delayed 00:08:32.001111 by SQLgrey-1.7.6 Received: from xigix.ioguix.net (ioguix.net [217.70.191.109]) by mail.postgresql.org (Postfix) with ESMTP id 6E6B264FC41 for ; Fri, 2 Jan 2009 14:17:58 -0400 (AST) Received: from xigix.ioguix.net (xigix.ioguix.net [217.70.191.109]) by xigix.ioguix.net (Postfix) with ESMTPSA id 50A6331CC7; Fri, 2 Jan 2009 19:09:23 +0100 (CET) Date: Fri, 2 Jan 2009 19:09:22 +0100 (CET) From: ioguix@free.fr X-X-Sender: ioguix@xigix.ioguix.net Reply-To: ioguix@free.fr To: Marc Fromm cc: "pgsql-admin@postgresql.org" Subject: Re: access data in php In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: Content-Type: TEXT/PLAIN; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8BIT X-Archive-Number: 200901/3 X-Sequence-Number: 31050 On Fri, 2 Jan 2009, Marc Fromm wrote: > If I gather the sql results with this code > $results = pg_query($dbconn,$query); >   > I can check if there is no returned data with this code > $rows = pg_fetch_assoc($result); >   > but if I then use a while loop to display data (if there is data returned) with this code  > while ($row = pg_fetch_array($result)){ . . . } >   > I have to execute this code a second time before the while loop > $results = pg_query($dbconn,$query); >   > If I do not execute the $results line a second time the while loop does not work properly. >   > Why is $results loosing its value when it hits the while loop? >   > Thanks >   > Marc pg_fetch_assoc behave like pg_fetch_array: it increments the internal pointer to the current result. So if you call it once, then pg_fetch_array will return the 2nd result in the result set. You can either : - use pg_fetch_assoc($result,0) whish shouldn't increment the internal pointer (no sure though, check http://php.net/pg-fetch-assoc) - seek back to the first result in the result set using pg-result-seek (http://php.net/pg-result-seek) - use pg_num_rows to get the number of rows in your result set. Happy new year ! -- Guillaume (ioguix) de Rorthais