Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Paging - pages are multiplying!

    Hi everybody,

    Exactly what the title says! And the funny thing is that if I click on page no.1 I get 10 results, if I click page no.2 I get 20 results, page no.3 30 results and so on... What am I doing wrong?

    Here's my code:

    PHP Code:
    <?
    if (!(isset($start))) { $start=0; }
    $maxperpage=10;
    $tend $start+$maxperpage

    SOME SQL QUERY = (" ... LIMIT $start,$tend")
    ?>
    ****HERE I GET THE SQL RESULTS-OUTCOME****

    and then towards the end of the page, I have the following code:

    <a href=URL&start=0\">1</a>");

    PHP Code:
    <?
    $more
    mysql_query("SELECT * FROM * WHERE *** ") or die(mysql_error());
    $more2mysql_num_rows($more);
    $maxpage ceil($divide/$maxperpage); 
    if ((
    $more2/$maxperpage)>$maxpage) { $maxpage=$maxpage+1; } 
    for (
    $j=1;$j<$maxpage;$j++){
    $cs = ($j*$maxperpage); $cp $j+1;
    print(
    " | <a href=URL&start=$cs>$cp</a>");  
    }
    ?>
    The outcome of the code above is like this:

    Pages: 1, 2, 3, 4, 5 etc.

    and every time I click on any number I get the SQL results-records multiplied by 10 (e.g. if I click on 3 I get 30 results per page, on 5 I get 50! etc).

    Any help would be GREATLY appreciated!
    Last edited by ron08; 03-12-2008 at 03:57 PM. Reason: php tags - newbie

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by ron08 View Post
    Hi everybody,

    Exactly what the title says! And the funny thing is that if I click on page no.1 I get 10 results, if I click page no.2 I get 20 results, page no.3 30 results and so on... What am I doing wrong?

    Here's my code:

    <?
    if (!(isset($start))) { $start=0; }
    $maxperpage=10;
    $tend = $start+$maxperpage;

    $ SOME SQL QUERY = (" ... LIMIT $start,$tend")
    ?>

    ****HERE I GET THE SQL RESULTS-OUTCOME****

    and then towards the end of the page, I have the following code:

    <a href=URL&start=0\">1</a>");

    <?
    $more= mysql_query("SELECT * FROM * WHERE *** ") or die(mysql_error());
    $more2= mysql_num_rows($more);
    $maxpage = ceil($divide/$maxperpage);
    if (($more2/$maxperpage)>$maxpage) { $maxpage=$maxpage+1; }
    for ($j=1;$j<$maxpage;$j++){
    $cs = ($j*$maxperpage); $cp = $j+1;
    print(" | <a href=URL&start=$cs>$cp</a>");
    }
    ?>

    The outcome of the code above is like this:

    Pages: 1, 2, 3, 4, 5 etc.

    and every time I click on any number I get the SQL results-records multiplied by 10 (e.g. if I click on 3 I get 30 results per page, on 5 I get 50! etc).

    Any help would be GREATLY appreciated!
    You're multiplying it in your code, the displaying the multiplied number in the link.

    Please remember to read the stickies for this forum. In particular the one about using [php][/php] tags when posting code.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    The second argument to LIMIT specifies the number of rows that are returned, and not an offset into the result set.

    That's why you have to change:
    PHP Code:
    $tend $start+$maxperpage
    to
    PHP Code:
    $tend $maxperpage
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •