Cleaner/more effective way to use modulus and creating columned lists
Posted
by WmasterJ
on Stack Overflow
See other posts from Stack Overflow
or by WmasterJ
Published on 2010-03-23T21:21:23Z
Indexed on
2010/03/23
21:23 UTC
Read the original article
Hit count: 393
I currently have a list (<ul>) of people that I have divided up into two columns. But after finishing the code for it I keept wondering if there is a more effective or clean way to do the same thing.
echo "<table class='area_list'><tr>";
// Loop users within areas, divided up in 2 columns
$count = count($areaArray);
for($i=0 ; $i<$count ; $i++) {
// get the modulus value + ceil for uneven numbers
$rowCalc = ($i+1) % ceil($count/2);
if ($rowCalc == 1) echo "<td><ul>";
// OUTPUT the actual list item
echo "<li>{$users[$uid]->profile_lastname}</li>";
if ($rowCalc == 0 && $i!=0) echo "</ul></td>";
}
echo "</table>";
Any ideas of how to make this cleaner or do it in another way?
© Stack Overflow or respective owner