+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: PHP Page Numbering - Pseudo Code

  1. #1
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    PHP Page Numbering - Pseudo Code

    Hey guys I am creating page numbering with PHP. If anyone is interested, here is my pseudo code so far. The comment areas show when things should be echod. Although, in some places I have wrote "echo etc etc", that's just because I changed my mind. You should be able to figure out roughly what I mean.
    PHP Code:
    <?
        
    if ($total_pages 1) {
            
    //beginning page number section
            //beginning page number label
            
    echo $current_page;
            
    //middle page number label
            
    echo $total_pages;
            switch (
    $current_page) {
                case 
    1:
                case 
    2:
                case 
    3:
                case 
    11:
                case 
    51:
                case 
    101:
                case 
    501:
                    break;
                default:
                    
    //first button
                    
    break;
            }
            if (
    $current_page 1) {
                
    //left arrow
            
    }
            if (
    $current_page >= 4) {
                
    //dots
            

            if (
    $current_page >= 3) {
                
    //$current_page - 2;
                //$current_page - 1;
            
    }
            
    //$current_page;
            
    if (($total_pages $current_page) >= 2) {
                
    //$current_page + 1;
                //$current_page + 2;
            
    }
            if (
    $total_pages >= ($current_page 10)) {
                
    //$current_page + 10;
            
    }
            if (
    $total_pages >= ($current_page 50)) {
                
    //$current_page + 50;
            
    }
            if (
    $total_pages >= ($current_page 100)) {
                
    //$current_page + 100;
            
    }
            if (
    $total_pages >= ($current_page 500)) {
                
    //$current_page + 500;
            
    }
            if (
    $current_page $total_pages) {
                if ((
    $total_pages $current_page) > 2) {
                    
    //dots
                
    }
                
    //right arrow
                
    switch ($total_pages $current_page) {
                    case 
    1:
                    case 
    2:
                    case 
    10:
                    case 
    50:
                    case 
    100:
                    case 
    500:
                        break;
                    default:
                        
    //last button
                        
    break;
                }
            }
        }
    ?>
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  2. #2
    Manager
    cabry's Avatar

    Status : cabry is offline
    Join Date: Apr 2009
    Location: Germany
    Posts: 1,463
    cabry will become famous soon enough

    I'd make this more dynamic. What if there're 2000+ pages? or 174? or 32?
    R.I.P. Bolek



    SPREAD THE COMMUNISM

  3. #3
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    $current_page and $total_pages will be filled with the respected values, so 32 and 174 would work fine.
    If you had 2000 pages and you were on page... hmm, 1, you would see...

    [Page 1 of 2000] [1] [2] [3] [11] [51] [101] [501] ... [>] [Last >>]

    And if you were on page 77 you would see

    [Page 77 of 2000] [<< First] [<] ... [75] [76] [77] [78] [79] [89] [129] [177] [577] ... [>] [Last >>]

    But I realised I still need to add milestones for going backwards, so the beginning of the above example should look like this;

    [Page 77 of 2000] [<< First] [<] ... [27] [67] [75] [76] [77] etc

    If I wanted to add extra milestone buttons this would be simple, but the website I am making this for won't have more than 500 pages, since this is for a small image gallery.

    Edit: Pseudo code for backward milestones:
    PHP Code:
            if ($current_page 500) {
                
    //$current_page - 500;
            
    }
            if (
    $current_page 100) {
                
    //$current_page - 100;
            
    }
            if (
    $current_page 50) {
                
    //$current_page - 50;
            
    }
            if (
    $current_page 10) {
                
    //$current_page - 10;
            

    This would come straight after the first switch statement.

    Another Edit: Here is my pseudo code that I have converted so that it should work, still need to test it though, oh, and I need to make it actually show the images on the current page too.
    PHP Code:
    <?
        
    include 'includes/SQL_connect.php';
        
    $current_page $_POST['page'];
        
    $result mysql_query("SELECT * FROM images");
        
    $total_pages mysql_num_rows($result);

        if (
    $total_pages && $current_page <= $total_pages && $current_page 0) {
            echo 
    '<div id="page_numbers"><ul>'//beginning page number section
            
    echo '<li><img src="ui_images/down.png"> Page '.$current_page.' of '.$total_pages.'</li>'//page x of y
            
    switch ($current_page) {
                case 
    1:
                case 
    2:
                case 
    3:
                case 
    11:
                case 
    51:
                case 
    101:
                case 
    501:
                    break;
                default:
                    echo 
    '<li><img src="ui_images/dleft.png"> First</li>'//first button
                    
    break;
            }
            if (
    $current_page 1) {
                echo 
    '<li><img src="ui_images/left.png"></li>'//left arrow
            
    }
            if (
    $current_page >= 4) {
                echo 
    '...'//dots
            

            if (
    $current_page 500) {
                echo 
    '<li>'.($current_page 500).'</li>'//$current_page - 500;
            
    }
            if (
    $current_page 100) {
                echo 
    '<li>'.($current_page 100).'</li>'//$current_page - 100;
            
    }
            if (
    $current_page 50) {
                echo 
    '<li>'.($current_page 50).'</li>'//$current_page - 50;
            
    }
            if (
    $current_page 10) {
                echo 
    '<li>'.($current_page 10).'</li>'//$current_page - 10;
            
    }
            if (
    $current_page >= 3) {
                echo 
    '<li>'.($current_page 2).'</li>'//$current_page - 2;
                
    echo '<li>'.($current_page 1).'</li>'//$current_page - 1;
            
    }
            echo 
    '<li id="selected_page">'.$current_page).'</li>'//$current_page;
            
    if (($total_pages $current_page) >= 2) {
                echo 
    '<li>'.($current_page 1).'</li>'//$current_page + 1;
                
    echo '<li>'.($current_page 2).'</li>'//$current_page + 2;
            
    }
            if (
    $total_pages >= ($current_page 10)) {
                echo 
    '<li>'.($current_page 10).'</li>'//$current_page + 10;
            
    }
            if (
    $total_pages >= ($current_page 50)) {
                echo 
    '<li>'.($current_page 50).'</li>'//$current_page + 50;
            
    }
            if (
    $total_pages >= ($current_page 100)) {
                echo 
    '<li>'.($current_page 100).'</li>'//$current_page + 100;
            
    }
            if (
    $total_pages >= ($current_page 500)) {
                echo 
    '<li>'.($current_page 500).'</li>'//$current_page + 500;
            
    }
            if (
    $current_page $total_pages) {
                if ((
    $total_pages $current_page) > 2) {
                    echo 
    '...'//dots
                
    }
                echo 
    '<li><img src="ui_images/right.png"></li>'//right arrow
                
    switch ($total_pages $current_page) {
                    case 
    1:
                    case 
    2:
                    case 
    10:
                    case 
    50:
                    case 
    100:
                    case 
    500:
                        break;
                    default:
                        echo 
    '<li>Last <img src="ui_images/dright.png"></li>'//last button
                        
    break;
                }
            }
            echo 
    '</ul></div>';
        }
    ?>
    Once again, another edit: herp derp, $total_pages will be the number of rows, not the number of pages I need to do $total_pages = $number_of_rows / $number_of_images_per_page; will fix soon if anyone actually cares
    Last edited by Spooky; 06-02-2011# at 00:35.
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  4. #4
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    Can't edit my last post, so sorry for double post.
    This is looking good so far and I've changed some things around so I can test it without entering test values into the database. When this is put into use I would not do it this way, but currently it gets the current page and the number of total pages from the URL. Here is what it looks like.



    Edit: lol, just realised that I totally messed up the lines xD but it's still understandable I guess
    Last edited by Spooky; 06-02-2011# at 02:53.
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  5. #5
    Manager
    cabry's Avatar

    Status : cabry is offline
    Join Date: Apr 2009
    Location: Germany
    Posts: 1,463
    cabry will become famous soon enough

    mhh this looks a little too long doesnt it?
    I would drop the switch thing, and make it more dynamic as I said. Post the first 3 pages, the last 3 and then +3/-3 from the current one in the middle.
    R.I.P. Bolek



    SPREAD THE COMMUNISM

  6. #6
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    It's completely dynamic...
    And I observed the page numbering of another popular forum and I used the same logic that I noticed from playing around with theirs. Sure it's quite big, but when you have that many pages I guess it needs to be that big to give the user many options.
    Check out the page numbering on this thread that has a lot of pages.
    Test my version here and tell me what you think isn't dynamic about it (although it's just a sample page without the main structure of the page it will become, and you cannot actually click anything yet ). Change the URL to what you desire to test it with.

    E: I have also made the buttons change the page now.
    Last edited by Spooky; 06-02-2011# at 03:45. Reason: Updated link to new testing page
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  7. #7
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    So, cabry, did you find anything static about my code? I've given you a while, surely you've found something to back up your allegations?
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  8. #8
    Manager
    cabry's Avatar

    Status : cabry is offline
    Join Date: Apr 2009
    Location: Germany
    Posts: 1,463
    cabry will become famous soon enough

    Didnt follow this thread anymore. But the whole switch thing makes it less dynamic imho. But that's just me.
    R.I.P. Bolek



    SPREAD THE COMMUNISM

  9. #9
    Member
    Spooky's Avatar
    Status : Spooky is offline
    Join Date: Jan 2011
    Location: Wales, UK
    Posts: 77
    Spooky is on a distinguished road

    But in what way is it making it less dynamic? I see no flaws...
    E: Are you even aware of what the switch does?
    If Jack Helped You Off Your Horse, Would You Help Jack Off His Horse?

  10. #10
    Manager
    cabry's Avatar

    Status : cabry is offline
    Join Date: Apr 2009
    Location: Germany
    Posts: 1,463
    cabry will become famous soon enough

    cba to go through your code tbh. I'd use more mathematics to handle that but that's just me.
    R.I.P. Bolek



    SPREAD THE COMMUNISM

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 23 users browsing this thread. (0 members and 23 guests)

     

Similar Threads

  1. Key code in use
    By Smeg in forum Modern Warfare
    Replies: 5
    Last Post: 11-28-2010#, 08:13
  2. iRcon Promo Code
    By Blunks in forum News and Announcements
    Replies: 2
    Last Post: 10-12-2010#, 15:42
  3. FpsOverload FaceBook page
    By Blunks in forum News and Announcements
    Replies: 20
    Last Post: 01-17-2010#, 17:32
  4. Video Game Cosplay Yearbook Page
    By Robot in forum News, Reviews and Tutorials
    Replies: 0
    Last Post: 05-02-2009#, 21:58
  5. The Konami Code Makes ESPN.com Magical!
    By Robot in forum News, Reviews and Tutorials
    Replies: 0
    Last Post: 04-28-2009#, 06:17

Tags for this Thread

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
mw3 | mw3 forum | Halo 4 | mw3 perks | iPhone 4 Case | uncharted 3 | 3ds forum | diablo 3 beta | GTA 5 | PS Vita Forum | PS Vita
$cronimage
LinkBacks Enabled by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32