<?php foreach($products as $product) : ?>
<li><a href="<?php echo base_url(); ?>main/products/<?php echo $product->id; ?>">
<?php echo $product->name; ?> </a></li>
<?php endforeach; ?>
So the code above get's all records in a DB
and generates links. 100 Records in the table - I want to split the design into 5 col. So I will do that in CSS
but I need to be able to enclose
<ul> on every 20 records</ul>
How can i count
the loop and do this?
Do like this , this will solve your problem
<?php
*$i = 0;*
echo "<ul>";
foreach($products as $product) :
if($i % 20 == 0) echo "</ul><ul>";
?>
<li><a href="<?php echo base_url(); ?>main/products/<?php echo $product->id; ?>">
<?php echo $product->name; ?> </a></li>
<?php
//if($i % 20 == 0) echo "</ul>";
$i += 1;
endforeach;
echo "</ul>";
?>
*edit- set $i = 0; since arrays count from [0] by setting it to [1] makes the first col
have 19 instead of 20. By setting it to [0] Each col has 20. :) Thanks again ~fabio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With