Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.