php - Best Way To Dynamically Achieve Offset and Limit Without Multiple Queries To The Database? -
php - Best Way To Dynamically Achieve Offset and Limit Without Multiple Queries To The Database? -
i had lightbox 1 time opened fetched brands database in list. problem list can quite long split brands out lists of 10 , floated them left filled lightbox horizontally rather vertically since there around 40 brands.
the initial problem code won't cover if suddenly, 10 brands added database since code doesn't business relationship them.
the other problems sense disgusted myself having used multiple queries wondering if offer pointers how accomplish below bit more elegance , efficiency:
$sql2 = "select page_id, name, url " . dbtable_sitemap ." parent_id=$frames , isactive=1 , isdeleted=0 order 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 " . dbtable_sitemap ." parent_id=$sitemap_designer_frames , isactive=1 , isdeleted=0 order 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 " . dbtable_sitemap ." parent_id=$sitemap_designer_frames , isactive=1 , isdeleted=0 order 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 " . dbtable_sitemap ." parent_id=$sitemap_designer_frames , isactive=1 , isdeleted=0 order 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 you:
$sql2 = "select page_id, name, url " . dbtable_sitemap ." parent_id=$frames , isactive=1 , isdeleted=0 order position asc"; $result2 = mysql_query($sql2, $db_conn); $i=0; while ($myrow = mysql_fetch_array($result2)) { if ($i % 10 === 0) { if ($i > 0) echo "</ol>"; echo "<ol>"; } echo "<li>dsoajda</li>"; $i++; } if ($i > 0) echo "</ol>";
php mysql refactoring
Comments
Post a Comment