Hi i have a foreach loop, but it is just showing everything in one long line, so I wanted to put it in a table like this
data1 data2 data3
data4 data5 data5
here is my loop:
<?php foreach( $products as $product ) { ?> <? echo $product ?>
I know if I remove the i will get a long lasting line. the data is being pulled from my DB.
Thanks
Have a look at this thread .
<?php echo('<table><tr>'); $i = 0; foreach( $products as $product ) { $i++; echo '<td>'.$product .'</td>'; if(i % 3==0) { echo '</tr><tr>'; } } echo'</tr></table>'; ?>
@samueal: If you have exactly 3 products, you'll insert an extra (empty) row.