1

So basically, this is how my paging query looks like at the moment:

    $limit = mysql_escape_string($_GET['pagenumber']);
    if (empty($limit)){
    $limit = "1";
    }

    $page = $limit * 10;
    $flim1 = $page / 10;
    $flim = $page - 10;

At the end of my query, I have this:

    ... LIMIT $flim, $page

Which should be from 1, 10 if the pagenumber is 1 and 10, 20 if the page number is 2. It works on the first page perfectly, but when I get to the second, there were 20 results, although when I echoed $flim and $page, they were 10 and 20. I cannot understand why!

I've heard about some double-query for paging. If you know a simple way to do this that is kind of like this one, please post a link. Will my method work?

1 Answer 1

6

Please see specification of LIMIT there is LIMIT offset,count So in your situation it would be LIMIT $flim,10

Full code:

$page = mysql_escape_string($_GET['pagenumber']);
if (empty($limit)){
$page = "1";
}
$items_per_page=10;
$offset = ($page-1)*$_items_per_page;

Then LIMIT $offset,$items_per_page

Additionally you would need count for all items to not get above max page

Sign up to request clarification or add additional context in comments.

4 Comments

also, if you do 1,10 and then 10,20 (or 10,10) you will display item #10 twice
Well, he made the mistake in his original question. just needed to point it out.
For some reason, it makes 0 - 10 on page one,then 10-10, then 20-10?
For some reason, it makes 0 - 10 on page one,then 10-10, then 20-10? edit Ok, I see it now, offset, count. So I learned something new today too :)! Thank you so much, great support!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.