Hi, i need to make the table create a new row every 5 for loops so that the data would like like x x x x x x x x x x x x x x x x x help appreciated
$newrow = 0; echo "<tr>"; for($i=0; $i<100; $i++){ echo "<td>data</td>"; $newrow++; if($newrow == 5) echo "</tr><tr>"; } PHP: Did not test the code. This code will give you basic idea that how can you do it.
You can also use the modulus operator to avoid many if/else statements or counter resetting. if ($newrow % 5 == 0) { echo "</tr><tr>\n"; } PHP:
Assuming you have an array of data items $items (could just as easily be a while loop fetching from the database): echo "<table>"; $column = 0; foreach ($items as $item) { if (!$column) echo "<tr>"; echo "<td>{$item}</td>"; $column++; $column %= 5; if (!$column) echo "</tr>"; } if ($column) echo "</tr>"; echo "</table>"; PHP: Untested but you can see what's going on...