View Full Version : Breaking a cycle

11-09-2009, 10:28 AM

I don't know if the title is correct for what I need so if its not the correct title sorry, i'm a beginner.

I'm trying to make a shopping cart and I'm extracting some info from a mysql datadabe, and here I have this code:

$sql = 'SELECT * FROM sets ORDER BY id';
$result = $db->query($sql);

$output[] = '<table width="100%" cellpadding="10" cellspacing="0" align="center">

<tr width="644" align="center">';

while ($row = $result->fetch()) {
$output[] = '
<td><table class="item">
<tr><td class="itemname">'.$row['name'].'</td></tr>
<tr><td class="imgtable"> <img class="testimage" width="161" height="204" src="'.$row['image'].'"> </td></tr>
<tr><td class="itemprice">$'.$row['price'].' USD</td></tr>
<tr><td> <a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a> </td></tr>
$output[] = '</tr>


echo join('',$output);

that code is showing me this ( with the info i have in the database ):

But what I want is, after 4 items that have been listed the cycle should break and start a new one to display the next items ( making a new table to display another 4 items ) until there are no more items.

as you see in the image there are 5 items, well instead of that I want only 4 items and then display another 4 items BELOW.

something like this:

what do I need to add to the code above to do this?

Thanks !