Take the 2-minute tour ×

I'm using a PHP array that is gathering data from a mysql database. I'm outputting this info in a table, but the table is too long with all the entries from the DB for my liking. Since it outputs about 20 listings, and only 10 would fit nicely in the table without scrolling,

how would I code my PHP to output 10 database rows (the table is in a while loop, already), each in their own listing BUT THEN when it reaches 10, create a new column right next to the first one, and output the next 10?

share|improve this question
Show us what you have tried. –  Kermit Oct 25 '12 at 19:52
when you say "create new column in table", do you mean a mySQL database table or an HTML table? The question is quite ambiguous, although I guess you mean the latter. –  Spudley Oct 25 '12 at 20:07
Sorry. A HTML Cell <td> (new one of those) –  BiTZOiD Oct 27 '12 at 20:53

1 Answer 1

up vote 0 down vote accepted
  1. Do the query.
  2. Count the results. [ie. 30]
  3. Divide by the max number of rows you want to display. [ie. 10]
  4. Write an outer for loop to write the rows. [ie. from 1 to 10]
  5. Write an inner for loop to write the cells. [ie. from 1 to 3]
share|improve this answer
Thanks, that is easy enough. –  BiTZOiD Oct 27 '12 at 21:00
Can I Get An Example? –  BiTZOiD Oct 27 '12 at 21:34

Your Answer


