Jump to content


Photo

displaying multiple data


  • Please log in to reply
1 reply to this topic

#1 veenasv

veenasv
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNewyork,USA

Posted 26 June 2003 - 04:35 PM

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?

#2 techiedude

techiedude
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 June 2003 - 07:46 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users