From: Lynna Landstreet <lynna@spidersilk.net>
To: PJ <af.gourmet@videotron.ca>
Cc: pgsql-php@postgresql.org
Subject: Re: display query results
Date: Wed, 30 Jul 2008 13:53:16 -0400
Message-ID: <4890AA8C.9080907@spidersilk.net> (raw)
In-Reply-To: <4890A871.3020906@videotron.ca>
References: <48909454.7040305@videotron.ca>
<82E74D266CB9B44390D3CCE44A781ED90B64DC@POSTOFFICE.cranel.local>
<4890A871.3020906@videotron.ca>
PJ wrote:
> I've been looking at the pg_fetch_* functions but do not understand one
> little bit.
> Using your suggestion gives a blank screen but var_dump($myarray) gives
> "bool(false)"
> And a var_dump($results) returns "resource(3) of type (pgsql result)
> while print_r($results) returns "Resource id#3"
> I'm totally lost. :(
> Perhaps my query isn't well formulated?
> What I am trying to locate (or print out) is the string found the
> "description" column whre the row in the "name" column is Alcohol.
> item_id || glossary_id || name || description
> 2 || 2 || Alcohol || One of thetwo major....
> blah...blah.. blah
You can't print the results of a query directly - the format they are
retrieved in is not just a regular PHP array. That's what the various
"fetch" options do - they pull the data out of the resultset into a
regular variable (single or array, depending on which one you use) so
that you can print it or otherwise treat it as a normal variable.
pg_fetch_result fetches a single value (string, integer, whatever it
might be) and stores it in a variable. You have to tell it exactly which
row and column from the result set you want. If you're only after one
value, use this.
pg_fetch_array and pg_fetch_assoc each fetch a whole row of data, as an
array. The different between them is that with the first one, the array
keys are just numbers, and with the second, it's an associative array
where the keys are the names of the columns in your database. If you've
only retrieved one row, but need more than one value from that row, use
one of these.
pg_fetch_all fetches *all* the rows from your result set, as a
multidimensional array. If your query is likely to have retrieved
multiple rows, use this.
Does that help?
Lynna
--
Spider Silk Design - web design and development
509 St Clair W Box 73576, Toronto ON Canada M6C 1C0
Tel 416.651.2899 - Cell 416.873.9289
http://www.spidersilk.net
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-php@postgresql.org
Cc: lynna@spidersilk.net, af.gourmet@videotron.ca
Subject: Re: display query results
In-Reply-To: <4890AA8C.9080907@spidersilk.net>
References: <48909454.7040305@videotron.ca> <82E74D266CB9B44390D3CCE44A781ED90B64DC@POSTOFFICE.cranel.local> <4890A871.3020906@videotron.ca> <4890AA8C.9080907@spidersilk.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