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 7 of 7
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    anyone has an example of pagination?

    Hello,

    Anyone has example of pagination?

    I have made but its very basic procedural.. Id like to make it functional

    this is my code .. accept critics.. ..
    PHP Code:
    if(isset($_GET['start']))
        {
        $start=$_GET['start'];
        $limit=$_GET['limit'];
        }
    else
        {
        $start=0;
        $limit=15;
        }


    $query="SELECT * FROM users LIMIT $start, $limit";
        $queryall="SELECT * FROM users";
        $result = dbquery($link,$query);
        $resultall=dbquery($link,$queryall);
        $numrows=mysql_num_rows($resultall);
        if(mysql_num_rows($result) < 1 )
        {    
            echo 'no results found';
        }
        else 
          {
              
            echo $num = $row[0];
               while($row=mysql_fetch_array($result))
        {
    <tr>
                        
        <td><? echo $row['username']  ?> </td>
        <td><? echo $row[firstname?></td>
        <td><? php echo $row[lastname?></td>
        <td><?php echo $row[email?></td>
        
    </tr>
        <?php
        
    }
    <
    tr><td colspan="6" align="center" height="20" class="table-list-title"><b>Result Page &nbsp;</b>
        <?
            
    $numofpages=$numrows/$limit;
            if((
    $numrows $limit)!=0)
            
    $numofpages=$numofpages+1;
            for(
    $i=1,$start=0;$i<=$numofpages;$i++)
            {
            echo 
    '<span class="char"><A href="'; echo $_SERVER["PHP_SELF"]; echo '?click=userlist.php&start='.$start.'&limit='.$limit.'">'.$i.' |&nbsp;</a></span>';
            
    $start=$start+$limit;
            }
            
    ?>
        
    </td></tr>
    <?php
        
    }
    ?>
    This code runs but, if you have any suggestions to make it more comprehensive, its really a big help.. thanks..

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    For a while i also looked for some solution how the split the query results into a number of pages (i needed it to show my search results) but i didn't find any better solution then with LIMIT XX, XY;

    And think think this solution is probably not so bad as you think, because every mysql query in cached on the server, so if you are on the second page, it schould not take so long for calculation results as on the first page.

  • #3
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    that code display by number, id like to have pagination that displays Previous and Next only...

  • #4
    New Coder
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Look, here is a nice example how to do it:
    http://www.php-mysql-tutorial.com/php-mysql-paging.php

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Full blown pagination class, highly flexible:

    http://www.firepages.com.au

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Fumigator View Post
    Full blown pagination class, highly flexible:

    http://www.firepages.com.au
    also found here
    http://www.codingforums.com/showthread.php?t=74614

  • #7
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    heres my two cents on simple pagination

    PHP Code:
    if(!isset($_GET['page'])) {
            
    $page 1;
        }
        else {
            
    $page $_GET['page'];
            
    $var 4;
        }

        
    $max_news 10// How many results per page
        
    $start = ($page $max_news) - $max_news;
        
    $i 0;
        
    $query mysql_query("SELECT * FROM gmap ORDER BY id DESC LIMIT $start, $max_news");
        while(
    $row mysql_fetch_array($query))
        {
            if(
    $i == 0){
                            echo 
    '<tr><td class="alt">'.$row['commentUsr'].'</td><td class="alt">'.$row['town'].','.$row['state'].'</td><td class="alt"><a id="mytable" class="link" href="map?id='.$row['id'].'">Veiw on Map</a></td></tr>';
                        }
                        else{
                            echo 
    '<tr><td>'.$row['commentUsr'].'</td><td>'.$row['town'].','.$row['state'].'</td><td><a id="mytable" class="link" href="map?id='.$row['id'].'">Veiw on Map</a></td></tr>';
                        }
                        
    $i++;
        }
        echo 
    "</table>";
        
    $sql mysql_query("SELECT * FROM gmap");
        
    $result mysql_num_rows($sql);

        
    $total_pages ceil($result $max_news);
        echo 
    "<div class='pages'>";
        if(
    $page 1)
        {
            
    $previous $page 1;
            echo 
    '<a href="?page=' $previous '" class="nextprev">Previous</a>';
        }
        else{
            echo 
    "<span span class=\"nextprev\">&laquo; Previous</span>";
        }

        for(
    $i 1$i <= $total_pages$i++){
            if(
    $i == $page){
                echo 
    "<span class=\"current\">".$i."</span>";
            }
            else{
                echo 
    '<a href="?page=' $i '">' $i '</a> ';
            }
        }

        if(
    $page $total_pages){
            
    $next $page 1;
            echo 
    "<a href='?page=" $next "/' class=\"nextprev\">Next &raquo;</a>";
        }
        else{
            echo 
    "<span class=\"nextprev\">Next &raquo;</span>";
        }
        echo 
    "</div>"
    you can see it live at http://labs.guthnur.net/gmapAPI/map.php


  •  

    Posting Permissions

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