Results 1 to 6 of 6

Thread: <<Previous 1,2,3,4,5,6 Next>>

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    philippines
    Posts
    245

    <<Previous 1,2,3,4,5,6 Next>>

    How will i do this? is this possible using PHP & MYSQL?

    like if i have 100 records u just want to show the first 10 then have a link like <<Previous 1,2,3,4,5,6 Next>> to navigate through the records..

    Thanks in advance.. ^^

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: <<Previous 1,2,3,4,5,6 Next>>

    This may not be the best way to do it but if you have an ID field for example you can select records based on that field.

    PHP Code:
    select from YourTable WHERE ID between 1 and 10 

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: <<Previous 1,2,3,4,5,6 Next>>

    This is what i use

    PHP Code:
    function Nav_Bar($page,$pages,$start_page,$count_page)
    {
        
    $Nav_Bar "Pages($page of $pages) [";
        if(
    $pages 1)
        {    
            if(
    $page 1)
            {
                
    $prev $page 1;
                
    $Nav_Bar .= "<a href=\"{$_SERVER['PHP_SELF']}?page=1\" style=\"font-weight:bold;\"> First </a> <a href=\"{$_SERVER['PHP_SELF']}?page=$prev\" style=\"font-weight:bold;\"> &lt; </a>";
            }
            if(
    $page>1)
            {
                
    $start_page = ($page 3);
            }
            
            
    $start_page $page <= $start_page;
            
    $start_page $page == $pages $pages $start_page;
            
    $start_page $start_page $start_page;

                                        
            for(
    $count_page $start_page;$count_page <= $pages$count_page++)
            {
                if(
    $count_page > ($start_page 6) || $count_page == 0)
                {
                    break;
                }
                if(
    $count_page == $page)
                {
                    
    $Nav_Bar .= " <b>$count_page</b> ";    
                }
                else
                {
                    
    $Nav_Bar .= "<a href=\"{$_SERVER['PHP_SELF']}?page=$count_page\"> $count_page </a>";
                }
            }
            if(
    $page $pages)
            {
                
    $next $page 1;
                
    $Nav_Bar .= "<a href=\"{$_SERVER['PHP_SELF']}?page=$next\" style=\"font-weight:bold;\"> &gt; </a> <a href=\"{$_SERVER['PHP_SELF']}?page=$pages\" style=\"font-weight:bold;\"> Last </a>";
            }
        }
        else
        {
            
    $Nav_Bar .= "<b>$page</b>";
        }
        
    $Nav_Bar .= "]";
        return 
    $Nav_Bar;

    And heres an example of using it by selecting values from a MySQL table called photos

    PHP Code:
    $page 1;
    $per_page 10;

    if(isset(
    $_REQUEST['page'])){
        if(
    $_REQUEST['page']!='' || is_numeric($_REQUEST['page'])){
            
    $page $_REQUEST['page'];
        }
    }

    $sql_max "SELECT * FROM photos";
    $max_results mysql_query($sql_max);
    $max_rows mysql_numrows($max_results);
    $pages ceil($max_rows $per_page);

    $offset = ($page 1) * $per_page;

    $query "SELECT * FROM photos ORDER BY ID ASC LIMIT $offset$per_page";
    $result mysql_query($query);

    $Nav_Bar Nav_Bar($page,$pages,$start_page,$count_page,$gallery); 

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    philippines
    Posts
    245

    Resolved Re: <<Previous 1,2,3,4,5,6 Next>>

    whoah! that's a lot of code.. i'll check it out.. and i have another problem. after inserting new values to my database(still don't know loops in PHP.. heheh ) my page gets stuck and become white.. how can i redirect it to somewhere else.. like in my main page perhaps.. sorry for all those questions.. my question is resolved.. just this next one.. hehehe

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: <<Previous 1,2,3,4,5,6 Next>>

    Nice code John....i might use it for a script i'll be working on soon

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: <<Previous 1,2,3,4,5,6 Next>>

    Its called pagination - the Hobo posted a function a while back which does this very well and I've linked to it in the FAQ:

    http://www.vbforums.com/showthread.p...51#post1988751
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width