unsider Posted July 11, 2008 Share Posted July 11, 2008 Obviously SQL pagination is the most effective, but is there a specific manner of coding which optimizes the pagination? Also if there's anything else you think I should know, let me have it Below method very effective, or no...? <?php $query = "SELECT COUNT(id) AS numrows FROM ...."; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; $nav = ' '; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; $first = ' '; } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; $last = ' '; } echo $first . $prev . $nav . $next . $last; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114354-solved-most-effective-way-to-paginate/ Share on other sites More sharing options...
.josh Posted July 11, 2008 Share Posted July 11, 2008 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/114354-solved-most-effective-way-to-paginate/#findComment-588073 Share on other sites More sharing options...
unsider Posted July 11, 2008 Author Share Posted July 11, 2008 :-X Oops, I'm sorry I haven't checked out the newly updated tutorial section since I've been back here, I didn't know we had one. Thanks crayon. Quote Link to comment https://forums.phpfreaks.com/topic/114354-solved-most-effective-way-to-paginate/#findComment-588076 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.