From: ioguix@free.fr
To: Marc Fromm <Marc.Fromm@wwu.edu>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: access data in php
Date: Fri, 2 Jan 2009 19:09:22 +0100 (CET)
Message-ID: <alpine.DEB.2.00.0901021900580.1850@xigix.ioguix.net> (raw)
In-Reply-To: <B0D7C0A3F35FE144A70312D086CBCA9B0213E18F15@ExchMailbox2.univ.dir.wwu.edu>
References: <B0D7C0A3F35FE144A70312D086CBCA9B0213E18F15@ExchMailbox2.univ.dir.wwu.edu>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: ioguix@free.fr, Marc.Fromm@wwu.edu
Subject: Re: access data in php
In-Reply-To: <alpine.DEB.2.00.0901021900580.1850@xigix.ioguix.net>
References: <B0D7C0A3F35FE144A70312D086CBCA9B0213E18F15@ExchMailbox2.univ.dir.wwu.edu> <alpine.DEB.2.00.0901021900580.1850@xigix.ioguix.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox