I have this code, which only shows the amount of products in multiples of 5.
I.E. theres 5 products, its displays them fine, but if theres 7, it only displays the first five.
I'm not sure how to solve this. I've tried several ways and don't seem to get anywhere.
I want it to show 5 per line. So if theres 7 items, it'll show the first 5 on the first line, the other two on a new line
This is the code
$sql = 'SELECT p.*
FROM ' . PRODUCTS_TABLE . " p
WHERE MONTH(FROM_UNIXTIME(added)) IN (MONTH(CURDATE()), MONTH(DATE_SUB(CURDATE(), INTERVAL 1 month)))
LIMIT 20";
$result = $db->sqlQuery($sql); $cntp = 0;
while($row = $db->sqlFetchRow($result))
{
$products[] = '<td align="center">
<a href="product.php?id='.$row['id'].'">
<img src="'.$db->config['prod_img_directory'].''.$row['img'].'" alt="'.$row['name'].'" border="0" />
<br/>'.$row['name'].'
<br/>Price: £'.$row['price'].'
</a></td>';
print $cntp." - ";
if(++$cntp == '5')
{
$pros[] = " <tr>\n".implode('' , $products)."</tr>\n";
$products = '';
$cntp = 0;
}
}
$db->sql_freeresult($result);
i know the problem comes from $cntp not reaching 5 again, but i'm not sure on how to make it work with amounts that are not a multiple of 5