How can I make a second page after x number of results are shown from mysql query?

Discussion in 'PHP' started by Anveto, Aug 20, 2011.

  1. #1
    I have a script that pulls some info from a database and displays it in a table, but it will show an unlimited amount of rows, so how can i for example add a second page to the results after lets say 20 results?

    $req = "SELECT *," . $table . ".id as id_res  from $table, $table1 where " . $table . ".player_id = " . $table1 . ".id order by player_name;";
      $res = mysql_query($req);
      $number = mysql_num_rows($res);
    PHP:
    Thanks for the help!
     
    Anveto, Aug 20, 2011 IP
  2. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #2
    
    $postsperpage=20;
    $start = isset($_POST['page']) && is_numeric($_POST['page'])?$_POST['page']*$postsperpage:0;
    $req = "SELECT *," . $table . ".id as id_res  from $table, $table1 where " . $table . ".player_id = " . $table1 . ".id order by player_name LIMIT ".$start.","$postsperpage";";
    $pages = ceil(mysql_result(mysql_query("SELECT COUNT(*)  from $table, $table1 where " . $table . ".player_id = " . $table1 . ".id order by player_name;),0)/$postsperpage);
    
    PHP:
     
    ssmm987, Aug 20, 2011 IP