Skip site navigation (1) Skip section navigation (2)

Re: display query results

From: Lynna Landstreet <lynna(at)spidersilk(dot)net>
To: PJ <af(dot)gourmet(at)videotron(dot)ca>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: display query results
Date: 2008-07-30 17:53:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php
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?


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

In response to


pgsql-php by date

Next:From: Raymond O'DonnellDate: 2008-07-30 18:44:09
Subject: Re: display query results
Previous:From: PJDate: 2008-07-30 17:48:51
Subject: Re: display query results

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group