Split Php Loop Into 2 Lists
I have built the following function, but is it possible to get it to split my lists from one into more so I can have a maximum of 8 's per
- ? function buildProdu
Solution 1:
You can add a counter, and when that counter reaches 8, you start a new ul
.
$counter = 1;
while ($rowProd = dbFetchAssoc($resultProd)) {
extract($rowProd);
if($counter % 8 == 0) {
$counter = 1;
echo"</ul><ul>";
}
echo"<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
counter++;
}
Solution 2:
Okay, instead of echoing the LIs right from the function I suggest you add them all to an array, once things are in an array, its always easier to manage.
Use array_chunk() on the final array of LIs and it will split it into groups of eight.
Post a Comment for "Split Php Loop Into 2 Lists"