Search the Community
Showing results for tags 'foreach limit'.
-
I have my website paginating files that are shown onscreen. How can I make it so the page only loads the first page's files and then when going on to the next page, it loads the files on that page? Basically what I am trying to do is reduce load time by not loading the files on the pages after page one until the user actually goes to a page after page one. index.php <?php $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1; $items_per_page = 10; $offset = ($current_page - 1) * $items_per_page; $items = glob("entries/*.php"); $total_items = count($items); $total_pages = ceil($total_items / $items_per_page); foreach (array_slice($items, $offset, $items_per_page) as $entry) { include $entry; } echo "<table summary=\"\" cellpadding=\"10\" cellspacing=\"0\" border=\"0\" class=\"global-links-menu\"><tr>"; if($current_page != 1) { $back_page = $current_page - 1; echo "<td ><p><a href='?page=$back_page'>Back</a></p></td>"; } else { $back_page = $current_page - 1; echo "<td ><p></p></td>"; } for($j=1;$j<=$total_pages;$j++) { if($j==$current_page) { echo "<td ><p>$current_page</p></td>"; } else { echo "<td ><p><a href='?page=$j' title='Page $j'>$j</a></p></td>"; } } if($current_page <= $total_pages - 1){ $next_page=$current_page+1; echo "<td ><p><a href='?page=$next_page'>Next Page</a></p></td>"; } else { echo "<td ><p></p></td>"; } /* foreach (glob("entries/*.php") as $filename) { include $filename; } */ ?> </table>
- 2 replies
-
- limit
- reduce load time
-
(and 2 more)
Tagged with: