Re: display query results - Mailing list pgsql-php

From Matthias Ritzkowski
Subject Re: display query results
Date
Msg-id b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com
Whole thread Raw
In response to display query results  (PJ <af.gourmet@videotron.ca>)
Responses Re: display query results
List pgsql-php
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

pgsql-php by date:

Previous
From: PJ
Date:
Subject: display query results
Next
From: Robert Treat
Date:
Subject: Re: display query results