I originally had a lightbox that once opened simply fetched all brands from a database which were in a list. The problem is that this list can be quite long so I split the brands out into lists of 10 and floated them left so that they filled the lightbox horizontally rather than vertically since there are around 40 brands.
The initial problem with my code is that it won’t cover if suddenly, another 10 brands are added to the database since my code doesn’t account for them.
The other problems are that I feel disgusted with myself having used multiple queries so I was wondering if anyone could offer any pointers about how to achieve the below with a bit more elegance and efficiency:
$sql2 = "SELECT page_id, name, url
FROM " . DBTABLE_SITEMAP ."
WHERE parent_id=$frames
AND isActive=1
AND isDeleted=0
ORDER BY position ASC
LIMIT 10";
$result2 = mysql_query($sql2, $db_conn);
if (mysql_num_rows($result2) > 0) {
echo '<ol class="subnav-glasses">';
while ($myrow2 = mysql_fetch_array($result2)) {
$this_sub_page_id = $myrow2["page_id"];
$this_sub_name = htmlentities($myrow2["name"]);
$this_sub_url = $myrow2["url"];
echo "\n<li><a href=\"$this_sub_url\" title=\"$this_sub_name\">$this_sub_name</a>";
echo '</li>';
}
echo "</ol>";
}
$sql3 = "SELECT page_id, name, url
FROM " . DBTABLE_SITEMAP ."
WHERE parent_id=$sitemap_designer_frames
AND isActive=1
AND isDeleted=0
ORDER BY position ASC
LIMIT 10
OFFSET 10";
$result3 = mysql_query($sql3, $db_conn);
if (mysql_num_rows($result3) > 0) {
echo '<ol class="subnav-glasses">';
while ($myrow3 = mysql_fetch_array($result3)) {
$this_sub_page_id = $myrow3["page_id"];
$this_sub_name = htmlentities($myrow3["name"]);
$this_sub_url = $myrow3["url"];
echo "\n<li><a href=\"$this_sub_url\" title=\"$this_sub_name\">$this_sub_name</a>";
echo '</li>';
}
echo "</ol>";
}
$sql4 = "SELECT page_id, name, url
FROM " . DBTABLE_SITEMAP ."
WHERE parent_id=$sitemap_designer_frames
AND isActive=1
AND isDeleted=0
ORDER BY position ASC
LIMIT 10
OFFSET 20";
$result4 = mysql_query($sql4, $db_conn);
if (mysql_num_rows($result4) > 0) {
echo '<ol class="subnav-glasses">';
while ($myrow4 = mysql_fetch_array($result4)) {
$this_sub_page_id = $myrow4["page_id"];
$this_sub_name = htmlentities($myrow4["name"]);
$this_sub_url = $myrow4["url"];
echo "\n<li><a href=\"$this_sub_url\" title=\"$this_sub_name\">$this_sub_name</a>";
echo '</li>';
}
echo "</ol>";
}
$sql5 = "SELECT page_id, name, url
FROM " . DBTABLE_SITEMAP ."
WHERE parent_id=$sitemap_designer_frames
AND isActive=1
AND isDeleted=0
ORDER BY position ASC
LIMIT 10
OFFSET 30";
$result5 = mysql_query($sql5, $db_conn);
if (mysql_num_rows($result5) > 0) {
echo '<ol class="subnav-glasses">';
while ($myrow5 = mysql_fetch_array($result5)) {
$this_sub_page_id = $myrow5["page_id"];
$this_sub_name = htmlentities($myrow5["name"]);
$this_sub_url = $myrow5["url"];
echo "\n<li><a href=\"$this_sub_url\" title=\"$this_sub_name\">$this_sub_name</a>";
echo '</li>';
}
echo "</ol>";
}
Some pseudo-code for you: