Re: display query results
От | Lynna Landstreet |
---|---|
Тема | Re: display query results |
Дата | |
Msg-id | 4890AA8C.9080907@spidersilk.net обсуждение исходный текст |
Ответ на | Re: display query results (PJ <af.gourmet@videotron.ca>) |
Список | 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? 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
В списке pgsql-php по дате отправления: