I looked here:
Array into a table with 5 cells in each row
but I cannot adapt my code..
I need to display PHP array results in a table.
The table needs to have 3 cells for each row.
I don’t know how to output the <tr> and </tr> every 3rd row, and I don’t know how to output the last </tr> in case the table contains a number of records which is not a multiple of 3.
Here is my code:
echo "<table>";
$num=mysql_numrows($result1);
$i=0;
while ($i < $num)
{
$aaa=mysql_result ($result1,$i,"aaa");
$bbb=mysql_result ($result1,$i,"bbb");
echo "
<td>$aaa $bbb</td> ";
$i++;
}
echo "</table>";
use the mod operator % to check for the third element. e.g.