dwex Posted January 23, 2011 Share Posted January 23, 2011 like if I'm displaying a hundred entries , my website will be super long in length so I wanna break those hundred entries into maybe like 12 per page . Then click next page or the page number to view the next 12. Quote Link to comment https://forums.phpfreaks.com/topic/225383-how-to-do-php-pages/ Share on other sites More sharing options...
dwex Posted January 23, 2011 Author Share Posted January 23, 2011 and also sort. Like I can click the headers of a table and it will sort out the content by number or alphabet that belongs to header's column Quote Link to comment https://forums.phpfreaks.com/topic/225383-how-to-do-php-pages/#findComment-1163900 Share on other sites More sharing options...
ignace Posted January 23, 2011 Share Posted January 23, 2011 It's called pagination. MySQL has 2 convenient "tools": SQL_CALC_FOUND_ROWS and found_rows() for use with pagination. SELECT SQL_CALC_FOUND_ROWS .. FROM .. WHERE .. LIMIT $offset, $count SQL_CALC_FOUND_ROWS hints MySQL to keep a total of all rows in the result set to be retrieved with found_rows(). SELECT found_rows() Returns the total rows in the result set as if the query was executed without the LIMIT-clause. This query has to be followed directly after SQL_CALC_FOUND_ROWS. $totalPages = ceil($foundRows / $count); You calculate the offset from the page number using the below formula: ($page - 1) * $count Where $page >= 1 and $count > 0 Quote Link to comment https://forums.phpfreaks.com/topic/225383-how-to-do-php-pages/#findComment-1163908 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.