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

Re: display query results

From: PJ <af(dot)gourmet(at)videotron(dot)ca>
To: Matthias Ritzkowski <matthiar(at)gmail(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: display query results
Date: 2008-07-30 17:48:51
Message-ID: 4890A983.2040005@videotron.ca (view raw or flat)
Thread:
Lists: pgsql-php
Doesn't work... and I feel totally lost. I don't understand the 
pg_fetch_* stuff at all.
One would think that my query should return the text that is in the 
field. The database is quite correct and does work with php since it 
comes from an older web-site that someone else programmed for me. I'm 
using it to practice and learn. :)

Matthias Ritzkowski wrote:
> Try this:
>
> $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'";
>          $result = pg_query($db, $query) or die("Error in query: $query.
>          " . pg_last_error($db));
>
>          // Print result on screen
> while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
>    foreach ($line as $col_value) {
>         echo $col_value."<br />";
>     }
>
>          pg_close($db);
>
>
> The result set is an array, You just need to loop through it. The php
> manual has some nice examples that helped me get started.
> --------------------------------
>
>
> Matthias Ritzkowski
>
>   


In response to

Responses

pgsql-php by date

Next:From: Lynna LandstreetDate: 2008-07-30 17:53:16
Subject: Re: display query results
Previous:From: PJDate: 2008-07-30 17:44:17
Subject: Re: display query results

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