By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,970 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,970 IT Pros & Developers. It's quick & easy.

Fetching a row in a array where the column number is unknown

P: 37
Hi thescripts team,

I am trying to retrive a array and display its contents in the page. However, this array will be dynamic, meaning it will have different sizes in each call (there is a function that will handle the display). My question is, how would I make php read the array where it doesnt need to know the number of columns it has? Any technique that I can implement?

Here's a part of the code that I am currently working on.

Expand|Select|Wrap|Line Numbers
  1. foreach ($rowarray as $row)
  2. {
  3.    echo $row[0];
  4.    echo $row[1];
  5.    echo $row[2];
  6. }
Thanks for your replies as always!
Jul 27 '07 #1
Share this Question
Share on Google+
3 Replies


P: 37
After posting this thread, I found out my answer. (through experiments).

Expand|Select|Wrap|Line Numbers
  1. foreach ($rowarray as $row)
  2. {
  3.     for($i=0;$i<count($row);$i++)
  4.     {
  5.         echo $row[$i]." ";
  6.     }
  7. }

Whew!
Jul 27 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, twinklyblue.

Check out mysql_fetch_assoc().
Jul 27 '07 #3

P: 37
hi pbmods,

thanks for your reply.. however, I am working with Postgres :) I am sure there is a corresponding equivalent for this function.. I can start from this. thanks
Aug 2 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.