GrizRule Posted March 16, 2014 Share Posted March 16, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/287006-only-loading-files-on-specific-pages/ Share on other sites More sharing options...
ginerjm Posted March 16, 2014 Share Posted March 16, 2014 Don't understand what you mean by "loading files on pages". Can you be a little more technical about this? Quote Link to comment https://forums.phpfreaks.com/topic/287006-only-loading-files-on-specific-pages/#findComment-1472773 Share on other sites More sharing options...
mac_gyver Posted March 16, 2014 Share Posted March 16, 2014 the code you posted, provided that lines 50-53 are actually commented out, WILL only include the 10 files that correspond to the requested page. if you are seeing more, then either your code isn't what you think or you are seeing a cached version of your page. btw - why do you have a ton of .php pages that you are trying to paginate this way? that indicates you have went to a lot of trouble and time creating and managing php pages instead of just storing the data that's present on these pages in a proper database. Quote Link to comment https://forums.phpfreaks.com/topic/287006-only-loading-files-on-specific-pages/#findComment-1472790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.