Jump to content

[SOLVED] how to display 3 items in a row and move to next row.


phpchris

Recommended Posts

Hi Anyone, please help!

 

I need help on how to display 3 items in a row and move to next row. I have a short piece of code here and hope someone out there could help me on this.???  ??? :-[

 

 

<tr>

<?

$query = "Select * from products";

$result = $db_mysql->query($sql);

while ($row = mysql_fetch_row($result))

{

for($i=0; i<2; $i++)

{

?>

<td><? echo $row[id] ?></td>

<?

}

 

}

?>

</tr>

 

The output display is 1 2 3 4 5 but I want it to be displayed like this

 

1 2 3

4 5 6

7 8 9

10 11 12

 

I would greatly appreciate if someone could help me on this.

 

THANK YOU!

 

 

try this (not tested):

 

<?php

<tr>
<?
$query = "Select * from products";
$result = $db_mysql->query($sql);
$count = 0;
while ($row = mysql_fetch_row($result)){
    if($count % 3 == 2){ //after every third one, php is starting a new line and sets count to 0 again
        ?>
        <tr></tr>
        <?php
        $count == 0;
    }
    ?>
    <td><?php echo $row[id] ?></td>
    <?php
    $count++;
}
?>
</tr>

 

i have edited a little thing, it should work now!

 

kind regards

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.