Re: display query results

Tomas Vondra <[email protected]>
Newsgroups gmane.comp.db.postgresql.php
Message-ID <[email protected]>
> 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

-- 
Sent via pgsql-php mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.