1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to creat a pagination in PHP?

Discussion in 'PHP' started by annyphp, Feb 15, 2011.

  1. annyphp

    annyphp New Member

    Joined:
    Dec 7, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    As a php developer, you will often be tasked to display large amounts of data to the user in some kind of easy to read format.
    I have some records, I want to display records page by page!
    Any one give tutorial about pagination in php?
    I found some php pagination scripts listed on the site PHPKode.com
     
  2. underground_devil

    underground_devil New Member

    Joined:
    Jan 24, 2011
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    PHP developer ,trainer
    Location:
    Punjab
    i send you my simple code for pagination

    PHP:
    <?php
    $q
    ="SELECT * FROM table_name";
    $p=mysql_query($q);
    $nr=mysql_num_rows($p);
    $t=$nr/5;
    $lim=$_GET['start']*;

    $q="SELECT * FROM table_name LIMIT $lim,5";
    $p=mysql_query($q) or die('query error');
    while(
    $r=mysql_fetch_array($p))
    {
        echo 
    $r['user']."<br>";   // fetching data
    }

    for(
    $i=0;$i<=$t;$i++)
    {
        
    $j=$i+1;
        echo 
    " [ <a href=index.php?p=5&start=$i>".$j."</a>] | "// change according to you page
    }


    ?>

    may be there would some easy method but i like to use this simple code :)
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Instead of fetching the complete data at the top you could use count(*) as well to make it more efficient.
     

Share This Page