New row in the table every 3 columns

3

I have a table that has to have 3 columns per row. The data from the 3 columns I get from the bank. My problem is that when I display 3 columns, I want the next results to appear on the bottom lines, ie display 3 at 3, but I'm not getting it, because the code I made it displays 2 and on the bottom line 1 and so on.

<table border="0" width="650">
<?php
$i = 1;
while($data2 = mysql_fetch_array($SQLContentCalendario)){
echo ($i % 3) ? '' : '<tr>';
echo '<td valign="top" width="200">';
...
echo '</td>';
echo ($i % 3) ? '' : '</tr>';
$i++;
}
?>
</table>
    
asked by anonymous 05.05.2015 / 02:04

1 answer

7
<table border="0" width="650">
<?php
    $i = 1;
    echo '<tr>';    
    while($data2 = mysql_fetch_array($SQLContentCalendario)){
            echo '<td valign="top" width="200">';
            ...
            echo '</td>';
        if(($i % 3) == 0){
            echo '</tr><tr>';
        }
    }
    echo '</tr>';
?>
</table>
    
05.05.2015 / 02:21