Jump to content

displaying multiple data


veenasv

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?

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.