SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot sifuhall's Avatar
    Join Date
    Jun 2001
    Location
    out of the sidehatch
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pagination routine

    Does anyone have a decent pagination routine for large recordsets?

    I found one of phpbuilder, but it isn't very good.

  2. #2
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is "pagination" in the context of database recordsets?

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will let you do the hard work and use the advance seach form yourself, but pagenation of results (splitting records up into several page views) is one of those topics that gets discussed often here, and for which plenty of code has been offered and discussed.

    It you do a search you will find some results. If you have a more specific problemn/question with some code, then by all means post it as others will surely help.


  4. #4
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pagenation of results
    Yes, it does help when the word that one is looking for has been correctly spelled. Thanks sid.

    FYI, "pagination" is a technique for newspaper production planning.

  5. #5
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Marshall it's Freddy that spelled it wrong! You're right pagination does mean the numbering of pages in a book, that is why it is used for splitting a web document onto a number of pages too, most computer language is real-world language just given a new meaning.

  6. #6
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Marshall it's Freddy that spelled it wrong!
    Heh. I've tried both spellings and neither returned relevant results. Google had no comments on the topic in relation to Web design. The only thread that sitepoint's Advanced Search returned with "pagination" or "pagenation" as the keyword was this one.

    I'll just take "pagination" to mean the act of breaking database query results into display sets of realistic screen length.

  7. #7
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah there's not a lot, you'll have used it before without knowing what it's called That happens all the time to me people are saying, "Oh you know X?" And I'm like "Errrr?" and I do know, just not the term.
    Anyway you're right there's nothing on search so here's one I just ripped out of phpBB's code (shhh!) and modified slightly for sinful
    PHP Code:
    function paginate($num_items$per_page$start_item$add_prevnext_text TRUE)
    {
            Global 
    $PHP_SELF;
         
    $total_pages ceil($num_items/$per_page);
            
    $pageurl $PHP_SELF "?";

        if( 
    $total_pages == )
        {
            return 
    "";
        }

        
    $on_page floor($start_item $per_page) + 1;

        
    $page_string "";

        if( 
    $total_pages )
        {

            
    $init_page_max = ( $total_pages ) ? $total_pages;

            for(
    $i 1$i $init_page_max 1$i++)
            {
                
    $page_string .= ($i == $on_page) ? "<b>$i</b>" "<a href=\"" $pageurl "&amp;start=" . ( ( $i ) * $per_page ) . "\">$i</a>";
                if( 
    $i <  $init_page_max )
                {
                    
    $page_string .= ", ";
                }
            }

            if( 
    $total_pages )
            {
                if( 
    $on_page 1  && $on_page $total_pages )
                {
                    
    $page_string .= ( $on_page ) ? " ... " ", ";

                    
    $init_page_min = ( $on_page ) ? $on_page 4;
                    
    $init_page_max = ( $on_page $total_pages ) ? $on_page $total_pages 3;

                    for(
    $i $init_page_min 1$i $init_page_max 2$i++)
                    {
                        
    $page_string .= ($i == $on_page) ? "<b>$i</b>" "<a href=\"" $pageurl "&amp;start=" . ( ( $i ) * $per_page ) . "\">$i</a>";
                        if( 
    $i <  $init_page_max )
                        {
                            
    $page_string .= ", ";
                        }
                    }

                    
    $page_string .= ( $on_page $total_pages ) ? " ... " ", ";
                }
                else
                {
                    
    $page_string .= " ... ";
                }

                for(
    $i $total_pages 1$i $total_pages 1$i++)
                {
                    
    $page_string .= ($i == $on_page) ? "<b>$i</b>"  "<a href=\"" $pageurl "&amp;start=" . ( ( $i ) * $per_page ) . "\">$i</a>";
                    if( 
    $i <  $total_pages )
                    {
                        
    $page_string .= ", ";
                    }
                }
            }
        }
        else
        {
            for(
    $i 1$i $total_pages 1$i++)
            {
                
    $page_string .= ($i == $on_page) ? "<b>$i</b>" "<a href=\"" $pageurl "&amp;start=" . ( ( $i ) * $per_page ) . "\">$i</a>";
                if( 
    $i <  $total_pages )
                {
                    
    $page_string .= ", ";
                }
            }
        }

        if( 
    $add_prevnext_text )
        {
            if(
    $on_page 1)
            {
                
    $page_string " <a href=\"" $pageurl "&amp;start=" . (($on_page 2) * $per_page) . "\">" "Previous" "</a>&nbsp;&nbsp;" $page_string;
            }

            if(
    $on_page $total_pages)
            {
                
    $page_string .= "&nbsp;&nbsp;<a href=\"" $pageurl "&amp;start=" . ($on_page $per_page) . "\">" "Next" "</a>";
            }

        }

        
    $page_string  "Goto page: " $page_string;

        echo 
    $page_string;


    Call it by paginate(total,per page, start of page your on)
    Last edited by mitsubishi; Dec 22, 2001 at 23:17.

  8. #8
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW I don't know if can post that here? The GPL confuses the heck out of me, you'll have to ask them if it's OK to use it. Oh and sorry sifuhall, not sinful

  9. #9
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using GPL'ed code in a project makes all code in that project GPL (open source) as well, and no additional restrictions can be added to the license. This means that you can do whatever you like with GPL'ed code as long as you don't try to keep it a secret ;-)

    - Marshall

  10. #10
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Who's on first?

    What a confused thread. My name is freakysid, and you should never trust that I know how to spel nuffin

    Pagination is not a term that I have heard often either. However, this search on "split page" should have some good results:

    http://www.sitepointforums.com/searc...der=descending


Bookmarks

Posting Permissions

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