I have a problem getting my head around having multiple returns in a query and formatting them so they are limited to say 12 but are left to right 6 then below the same, basically what I am trying to do is re- develop http://playrandom.com which has a similar lay out to the previous version was not php / database driven. The problem which I am coming across is that it is all well and good having them displayed below each other as the html pattern is the same, but in this instance there are two different html tags e.g. ….. <td>blar</td><td>blar</td><td>blar</td> after every 6 there is a </tr> which would put the next set of result below.
$query = mysql_query("...") OR die(mysql_error()); $rows = 0; echo '<table> <tr>'; while ($row = mysql_fetch_assoc($query)) { echo '<td>stuff here</td>' . "\n"; if (++$rows % 6 == 0) { echo "</tr><tr>\n"; } } echo '</tr> <table>'; PHP:
nice...i done it with declaring a variable $i and up it and never came to me that I could indeed use the $rows value
Note that I'm using 2 similar named variables. $row and $rows. $rows holds an increasing integer and $row the current row from the database.
Multiple of 6. % means modulus, the remainder when you divide a number by another eg. 5/2 = 2.5 or 2 with a modulus of 1 18/4 = 4.5 or 4 with a modulus of 2