veenasv Posted June 26, 2003 Share Posted June 26, 2003 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? Quote Link to comment https://forums.phpfreaks.com/topic/640-displaying-multiple-data/ Share on other sites More sharing options...
techiedude Posted June 26, 2003 Share Posted June 26, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/640-displaying-multiple-data/#findComment-2138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.