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
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    paging with for loop

    I'm trying to figure out the formula on how to page a file:
    ?page=1;
    ?page=2...
    And when page = 1 then what is called $startpage (not to be confused with the paging of the url) would start at 1.
    And when page = 2 then what is called $startpage would be 101.
    And when page = 3 then what is called $startpage would be 201.
    PHP Code:
    $totalPages=722;
    $url_page$_GET['page'];//grabs the page from the URL. The rest I can't figure  out if it's right.
    for($thisPage 1$thisPage <= $totalPages$thisPage $thisPage+100 ){
        
    $startpage $thisPage;
    }
    $num_pages 100

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    I think I almost figured it out:
    PHP Code:
    /*
    $totalPages=722;
    $url_page= $_GET['page'];
    $num_pages = 100;
    for($thisPage = 1; $thisPage <= $totalPages; $thisPage = $thisPage+$num_pages ){
        $startpage = $thisPage;
    }
    */
    $num_pages 100;//is the number of html pages inserted in a database per minute because online servers can't do all at once
    $totalPages=722;//is the total amount of pages of html that exist
    $end_url_page$totalPages/$num_pages;//is LAST page of this file's url. This file will repeat every minute due to the 1 minute rule for online servers with the extension?page=1, ?page=2...
    $url_page$_GET['page'];//is PRESENT page of this file's url.
    $startpage = (($url_page ) * $num_pages) + 1;//is the present html page to be inserted in the database 
    I tried to be as detailed as possible. If there are any more questions let me know thanks!

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    PHP Code:
    $startpage = (isset($_GET['page'])) ?
      (((int) 
    $_GET['page']) - 1) * $num_pages :
      
    1
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by dumpfi View Post
    PHP Code:
    $startpage = (isset($_GET['page'])) ?
      (((int) 
    $_GET['page']) - 1) * $num_pages :
      
    1
    dumpfi
    That looks neat but I wish I knew what this would do!

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    inline conditional...just break it down:
    Code:
      if isset $_GET['page'] then
          $startpage = (((int) $_GET['page']) - 1) * $num_pages + 1
      else
          $startpage = 1

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Brandoe85 View Post
    inline conditional...just break it down:
    Code:
      if isset $_GET['page'] then
          $startpage = (((int) $_GET['page']) - 1) * $num_pages + 1
      else
          $startpage = 1
    What's the difference then between this and
    PHP Code:
    $startpage = (( $_GET['page'] - ) * $num_pages) + 1
    ?

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    How do you make it so that if the url has no ?page=1 extension then there has to be an assumption that it is 1?
    This didn't work:
    PHP Code:
    if($_GET['page']==''){
        
    $url_page 1;
        }else{
        
    $url_page $_GET['page'];
        } 


  •  

    Posting Permissions

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