Re: display query results

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: PJ <af(dot)gourmet(at)videotron(dot)ca>
Cc: Lynna Landstreet <lynna(at)spidersilk(dot)net>, pgsql-php(at)postgresql(dot)org
Subject: Re: display query results
Date: 2008-07-30 21:33:58
Message-ID: 4890DE46.9020208@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

> Well, it does explain things a little. Unfortunately, I have tried about
> everything imaginable before posting except the right thing.
> I can not visualize what it is that my query is returning. Here is what
> the code is:
>
> <?php
> $db = pg_connect("host=localhost port=5432 dbname=med user=med
> password=0tscc71");
>
> if (!$db)
> {
> die("Could not open connection to database server");
> }
>
> // generate and execute a query
> $query = "SELECT description FROM glossary_item WHERE
> name='Alcohol'";
> $results = pg_query($db, $query) or die("Error in query: $query.
> " . pg_last_error($db));
> var_dump ($results);
> $val = pg_fetch_result($results, 1, 3);
> echo $val, "\n";
> pg_close($db);
> ?>
>
> Whatever I enter as values for pg_fetch_result, the screen output is :
>
> resource(3) or type (pgsql result)
> *Warning*: pg_fetch_result() [function.pg-fetch-result
> <http://biggie/k2/function.pg-fetch-result>]: Unable to jump to row 1 on
> PostgreSQL result index 3 in
> */usr/local/www/apache22/data/k2/test1_db.php* on line *29*
> I don't understand what $resuts is returning - if it is an entire row,
> the one that the field is in that I am looking for, then why do I not
> get a printout of the text that is in that field? The row in the table
> is the second row and the field I am trying to retrieve is the 4th field.
> Am I querying correctly? The table is "glossary_item", the row I want is
> the one that is unique in containing the word "Alcohol" in the column
> "name"
>
> I changed: $query = "SELECT * FROM glossary_item WHERE name= 'Alcohol'";
> same result
>
> Picture me tearing out my hair...

Have you tried running the query from psql (or any other SQL interface)?
This warning means there are no rows in the result, so it can't skip to
the second row in it (the first row has index 0).

Tomas

In response to

Browse pgsql-php by date

  From Date Subject
Next Message PJ 2008-07-30 21:46:23 Re: display query results
Previous Message Tomas Vondra 2008-07-30 21:30:26 Re: display query results