Reputation: 4337
all i want to do is end the current, and begin a new UL every 10 results
heres my code which isn't working 100%:
$sql1 = mysql_query("select * from `provinces` order by `name` asc");
while ($row1 = mysql_fetch_assoc($sql1))
{
echo '<li id="popup_'.strtolower(str_replace(' ', '_', $row1['name'])).'">';
echo '<ul>';
$sql2 = mysql_query("select * from `cities` where `id_province`='".$row1['id']."' order by `name` asc");
$count = 1;
while ($row2 = mysql_fetch_assoc($sql2))
{
if ($count % 10 == 0)
echo '</ul>';
echo '<li>'.$row2['name'].'</li>';
if ($count % 10 == 0)
echo '<ul>';
$count++;
}
echo '</ul>';
echo '</li>';
}
Upvotes: 1
Views: 190
Reputation: 287
so it should work with new ul AFTER 10 results... if you want it BEFORE every 10th result you have to set the if block before the li output
$sql1 = mysql_query("select * from `provinces` order by `name` asc");
while ($row1 = mysql_fetch_assoc($sql1))
{
echo '<li id="popup_'.strtolower(str_replace(' ', '_', $row1['name'])).'">';
echo '<ul>';
$sql2 = mysql_query("select * from `cities` where `id_province`='".$row1['id']."' order by `name` asc");
$count = 1;
while ($row2 = mysql_fetch_assoc($sql2))
{
echo '<li>'.$row2['name'].'</li>';
if ($count % 10 == 0)
echo '</ul><ul>';
$count++;
}
echo '</ul>';
echo '</li>';
}
Upvotes: -1
Reputation: 48101
replace this
if ($count % 10 == 0)
echo '</ul>';
with
if ($count % 10 == 0)
echo '</ul><ul>';
And completly remove the second check
if ($count % 10 == 0)
echo '<ul>';
Otherwise your html screws up
// took me some time to get this answered because the problem was not easy to indentify :)
Upvotes: 5