treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] PHP paging problem!

  • This is basically my paging system right now:
    <?php
    $limit = mysql_escape_string($_GET['p']);
    if (empty($limit)){
    $limit = "1";
    }
    $page = $limit * 10;
    $flim1 = $page / 10;
    $flim = $page - 10;
    /* So basically, the 'p' is the page number, and $flim is "from" and $limit is "to"
    so this is at the end of the query I use to get my posts, feed or whatever */
    ... LIMIT $flim, $page");
    ?>

    In my login, this would mean that if the page number is one, it would chose everything from 1 to 10, which is correct. But when I come to page number two, i get 20!

    Can you see something I'm doing wrong here?
  • What do you want to achieve? When I use the following:

    <?php
    $limit = mysql_escape_string($_GET['p']);
    if (empty($limit) ){
    $limit = "1";
    }
    $page = $limit * 10;
    $flim = $page - 10;
    echo $flim ."-". $page;
    ?>


    I get the following output:

    p=1
    0-10


    p=2
    10-20


    p=5
    40-50


    What do you think I should be getting?
  • @BenWalker - I should mark this as solved. I misunderstood the "LIMIT" in mysql, I thought it was FROM, TO, but it is FROM, AMOUNT - so I figured it out :)