Re: display query results

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

-- 
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.