Jump to content

pagination


dudejma

Recommended Posts

Is there a way of doing pagination other than going through the whole big file, like:

 

$limit = "LIMIT 0, 30";
if ($_GET['page'] == 2) {
$limit = "LIMIT 30, 30";
}
$sql = "SELECT * FROM table WHERE blah = 'blah' $limit";
$result = mysql_query($sql);

 

But is there a way to do this without having to write an if statement for each page without getting to extensive? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/255040-pagination/
Share on other sites

you can google this and find many results, but basically you will set the mysql offset and limit to variables, and when a page is clicked, set the offset to (page_number * number of things per page) and the limit to (page_offset - number of things per page).

Link to comment
https://forums.phpfreaks.com/topic/255040-pagination/#findComment-1307743
Share on other sites

As AyKay47 pointed out already.

 

Here's a pagination script and demo I did, might be able to see the process better.

 

http://get.blogdns.com/paginate/

 

As can see there is a startrow(mysql starting row begins at zero) and a posts_per_page(how many results are displayed each page) in the query.

It uses math to determine what the mysql starting row will be depending on the page number and how many posts per page are displaying.

 

$result = mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT $startrow,$posts_per_page"); 

 

It would be better to have the $startrow dynamic in the query, not checking with multiple if's and setting the values for each page like you are.

 

There's a complete pagination tutorial at phpfreaks.

http://www.phpfreaks.com/tutorial/basic-pagination

 

Link to comment
https://forums.phpfreaks.com/topic/255040-pagination/#findComment-1307754
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.