Jump to content

Archived

This topic is now archived and is closed to further replies.

veenasv

displaying multiple data

Recommended Posts

Hi,

I am retreiving set of information from postgresql database. I am taking 3 columns of a table in my select query. this returns multiple rows.

How can display each column of a row for all the rows retrieved in php?

I tried couple of things with pg_fetch_array but it doesn\'t display the data what I need.

 


$query="select a,b,c from xyz where ..."; //this retrieves say 3 rows

$result=pg_query($query);

$rows=pg_numrows($result);

if($rows>0)

{

    for($i=0;$i<$rows;$i++)

    {

        $data=pg_fetch_array($result,$i); // now $data contains each row

     }

}





 

 

I am just giving piece of code. With pg_fetch_array, will I get all the 3 columns of a row? I am not able to access the second and third column with the above code. It just gives me the first column in all the 3 rows which are retrieved.

 

Can anybody advice how to achieve this?

Share this post


Link to post
Share on other sites

First off, did you make sure that your query actually returns real data?

 

If it did, then your variable $data will contain the results of each row within each iteration of your for loop. pg_fetch_array will only return the data for the row you are specifying

 

Try using print_r($data) to see if there\'s anything in there:

$data is an array with each column represented as an item in the array

so:

$data[\'a\'] contains column data for a, so does $data[0]

$data[\'b\'] contains column data for b, so does $data[1]

etc.

 

hope that answers your question.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.