PHP while loop, table row
- by Elliott
Hi, I'm trying to loop through a database and output data into a div, if there are 3 divs horizontally accross it will the start a new tr until it reaches another 3 etc. It is currently outputted like :
[] [] []
[]
[] []
Currently I have it working when it reaches 3 it starts a new row, but I don't know how I can only echo a new tr once? As it creates a new table row each time.
echo '<table><tr>';
while ($result)
{
$i ++;
if ($i&3)
{
echo '<td>
<div>Row Data</div>
</td>';
}
else
{
echo '<tr>
<td>
<div>Row Data</div>
</td></tr>';
}
}
echo '</tr></table>';
The $result variable is the recordset from my sql query, everything works fine I just don't know how to only create a new table row once?
Thanks