I need to display many pages of news in a site. Should I do the pagination in the database query using LIMIT
or with the PHP script after getting all the results?
$query = "SELECT * FROM page LIMIT $start, $per_page "; //page bottom, where you want to put your numbers $pages=ceil($num/$per_page); for($s=1; $s<=$pages; $s++) { if($s==$page) $numPage . = "[$s] "; else $numPage . = "<a href='index.
$currentPage = ceil(($startIndex - 1) / $itemsPerPage) + 1; I used ceil() to make sure you have an integer number, which is rounded up so the current page number is correct.
Use limit in SQL! Every time!
Otherwise you're throwing around considerably more data than you need to, which makes your scripts unnecessarily slow, and will lead to scalability problems as the amount of data in your tables increases.
Limit is your friend!
Use limit - you don't want to transfer masses of data from the database to the scripting engine if you can avoid it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With