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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Pagination with max 10 pages

    Hi all,

    I'm trying to get some pagination to my results page.
    I would like the navigation links to only show 5 pages on either side of the current page.

    For example if I have 40 pages in total:

    Page 1 shows:
    1 2 3 4 5 6 7 8 9 10 [Last] Next

    Page 18 shows:
    [First] 14 15 16 17 18 19 20 21 22 23 [Last]

    Currently I have all the page links (1-40 echoed) by using this tutorial:
    http://www.phpbuilder.com/tips/item.php?id=2

    I'm using Oracle, but if anyone can point me to a mySQL example of the above, I'm sure I can replicate it in Oracle/PHP.

    Hope someone can help as I'm completed stumped!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    There's a good snippet posted by Fou-Lu at PHP5 Pagination
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks for the reply.
    Jeepers! thats some fancy code. No idea if I'll ever be able to implement that as I've only been doing PHP for a couple of weeks lol

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    You have to add some if statements - or modify the curent ones - to the code below.


    PHP Code:
    // Now loop through the pages to create numbered links 
    // ex. 1 2 3 4 5 NEXT >>
    for ($i=1;$i<=$pages;$i++) { 
        
    // Check if on current page 
        
    if (($offset/$limit) == ($i-1)) { 
            
    // $i is equal to current page, so don't display a link 
            
    echo "$i &nbsp; "
        } else { 
            
    // $i is NOT the current page, so display a link to page $i 
            
    $newoffset=$limit*($i-1); 
            echo  
    "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n"
        } 


    Below is just an example and may have math and syntax errors, but should give you an idea where to start. You will have to come up with something for the last, first and next links, but since you know the current page and how many pages there will be that should be easy.

    The current page is ( $i ) and you can use some math to display links that fall within a range.

    PHP Code:
    $min $i 5;
    $max $i 5;

    if (
    $i >= $min) && ($i <= $max) {
    echo 
    links


    -----------
    Last edited by Len Whistler; 02-05-2010 at 07:41 PM.
    Leonard Whistler

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You can use my pagination class (in my signature). There's an example on how to use it on my site along with the source, and shouldn't be too hard to convert to oracle. if you get stuck in any way let me know
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by JAY6390 View Post
    You can use my pagination class (in my signature). There's an example on how to use it on my site along with the source, and shouldn't be too hard to convert to oracle. if you get stuck in any way let me know
    I'll vouch for Jay's pagination code, it's awesome! I got it just to see if I could integrate it into a project, and it worked awesome. Sadly, it would have taken me too much time to integrate it across all the needed pages, so I had to scrap using it, but the script is incredibly well-written and easy to use/customize. Well done, Jay.

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Thanks JohnDubya!
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    You can use my pagination class (in my signature). There's an example on how to use it on my site along with the source, and shouldn't be too hard to convert to oracle. if you get stuck in any way let me know
    Thanks Jay
    I'm new to PHP so I'm not sure where to start with changing your class to work with Oracle. I know Oracle doesn't do LIMIT or mysql functions like mysql_num_rows. But thats about the extent of my knowledge

  • #9
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I've not used oracle with PHP before, but there are alternatives to the limit clause
    http://www.oracle.com/technology/ora...o56asktom.html
    It's pretty complex by the looks of it
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #10
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Yes Oracle does have me cursing at time lol.
    I might persevere with the original code and Len's suggestions, as its partly working at least

    I'll post back with code if I figure it out...


  •  

    Posting Permissions

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