New row in table every 3 columns

Asked

Viewed 1,006 times

4

I have a table that has to have 3 columns per row. The data of the 3 columns I take from the database. My problem is that when I display 3 columns, I want the next results to appear in the bottom rows, ie, display 3 by 3, only I’m not getting it, because the code I made it displays 2 and the bottom row 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>

1 answer

8


<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.