paging like google

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khalidbaloch
    New Member
    • Oct 2006
    • 61

    paging like google

    can any one help me creating a dynamic pagination script for non-sql entries
    i made this simple paging script

    Code:
    <?php
    //Show Result Per Page
    $ResultPerPage=10;
    //Total Result Availaible
    $TotalResults =1000;
    //calculate how many pages will be created
    $TotalPages = $TotalResults / $ResultPerPage;
    $TotalPages = round($TotalPages,0);
    $c = 0;
    echo "<br>";
    
    while($c<$TotalPages){
    
    $page = $c + 1;
    if($_REQUEST['page']==$page){
    echo "[$page]";
    }
    else{
    echo "<a href=?page=$page>[$page] </a>";
    }
    $c = $c+1;
    }
    echo "<br>".$TotalResults." Pages in total".$TotalPages."<br>";
    ?>
    it displays all the following:

    [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] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90] [91] [92] [93] [94] [95] [96] [97] [98] [99] [100]
    1000 Pages in total100

    Can anyone help me to shorten the list of displaying page links? I want to do some like this:

    [1 ][2] [3] [4][ 5] [6 ][7 ][8][ 9] [10]

    and if the vistor is looking the page no 9 it should look like this

    [10][11][12][13][14][15][16][17][18][19]

    in short only last ten page links should be displayed instead all of 100 pages

    i have searched the web and found many paging script but all of theme was for mysql
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by khalidbaloch
    can any one help me creating a dynamic pagination script for non-sql entries
    i made this simple paging script

    Code:
    <?php
    //Show Result Per Page
    $ResultPerPage=10;
    //Total Result Availaible
    $TotalResults =1000;
    //calculate how many pages will be created
    $TotalPages = $TotalResults / $ResultPerPage;
    $TotalPages = round($TotalPages,0);
    $c = 0;
    echo "<br>";
    
    while($c<$TotalPages){
    
    $page = $c + 1;
    if($_REQUEST['page']==$page){
    echo "[$page]";
    }
    else{
    echo "<a href=?page=$page>[$page] </a>";
    }
    $c = $c+1;
    }
    echo "<br>".$TotalResults." Pages in total".$TotalPages."<br>";
    ?>
    it displays all the following:

    [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] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90] [91] [92] [93] [94] [95] [96] [97] [98] [99] [100]
    1000 Pages in total100

    Can anyone help me to shorten the list of displaying page links? I want to do some like this:

    [1 ][2] [3] [4][ 5] [6 ][7 ][8][ 9] [10]

    and if the vistor is looking the page no 9 it should look like this

    [10][11][12][13][14][15][16][17][18][19]

    in short only last ten page links should be displayed instead all of 100 pages

    i have searched the web and found many paging script but all of theme was for mysql
    [PHP]
    $start = $c;
    while($c<$Total Pages && $c<($start+10)) {
    $page = $c + 1;
    if($_REQUEST['page']==$page){
    echo "[$page]";
    }
    else{
    echo "<a href=?page=$pag e>[$page] </a>";
    }
    $c = $c+1;
    }
    [/PHP]
    That should do ya.

    Comment

    • tejasonduty
      New Member
      • Feb 2007
      • 1

      #3
      what if I want to have output like [1][2][3][4][5] [6] [7][8][9][10][11] Where current page is 6 and I want page to show 5 page back and 5 page forward/

      Comment

      • smdf
        New Member
        • Feb 2007
        • 6

        #4
        Can you please telll me what $c stands for. Is that representing the current page number? Also, I more or less have this same code belong but I definately have the same problem. Its paginating 82 pages and I only want to show 10 at a time. I'm using a for loop. I see you have $start but I dont see where and how you are using it effectively in the code you provided. Can you explain how you are using the $start variable in a little bit more detial or re-write the entire script. I need this to code write for my job and I'm pulling my hair out over here.

        Originally posted by b1randon
        [PHP]
        $start = $c;
        while($c<$Total Pages && $c<($start+10)) {
        $page = $c + 1;
        if($_REQUEST['page']==$page){
        echo "[$page]";
        }
        else{
        echo "<a href=?page=$pag e>[$page] </a>";
        }
        $c = $c+1;
        }
        [/PHP]
        That should do ya.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          smdf: you are not seriously 'suggesting' that b1randon re-writes his code for you!
          Originally posted by smdf
          Can you explain how you are using the $start variable in a little bit more detial or re-write the entire script. I need this to code write for my job and I'm pulling my hair out over here.
          This is not a coding factory but a forum where programmers help programmers.

          And if you are a PHP programmer you can work out how the variables $c and $start are used. It is not that difficult to see.

          moderator

          Comment

          • smdf
            New Member
            • Feb 2007
            • 6

            #6
            I can figure out how $c is being used. I'm just trying to figure out how to offset my paginating links without using PEAR. If he doesnt want to retype , cool, but I still don't see how $start is being used although I understand what its for. If he didn't need to explain $start then this forum wouldn't need to exist. If everyone knew how to use $start then then would have already knew the problem to offsetting paginating links.

            Originally posted by ronverdonk
            smdf: you are not seriously 'suggesting' that b1randon re-writes his code for you!
            This is not a coding factory but a forum where programmers help programmers.

            And if you are a PHP programmer you can work out how the variables $c and $start are used. It is not that difficult to see.

            moderator

            Comment

            • smdf
              New Member
              • Feb 2007
              • 6

              #7
              Originally posted by tejasonduty
              what if I want to have output like [1][2][3][4][5] [6] [7][8][9][10][11] Where current page is 6 and I want page to show 5 page back and 5 page forward/
              Hey, I just figured out my own problem and did exactly what you are looking for. You have to change the variable you are passing in the URL from the ones I am dealing with but here is how I went about it with a switch statement.



              <?php
              switch(TRUE){
              case ($c <= 10):
              if ($num_pages > 10 ) {
              $stop = $i + 10;}
              else {
              $stop = $num_pages; }

              for ($i=1; $i <= $stop; $i++)
              {
              if($i == $c)
              {echo ($i." ");}
              else
              {
              $urlquery = "q=".urlencode( $q)."&ist=".url encode($ist)."& pt=".urlencode( $pt)."&b=".urle ncode($b)."&d=" .urlencode($d). "&k=".urlencode ($k)."&pr=".url encode($pr)."&o =".urlencode($o )."&s=".urlenco de($s)."&c=".ur lencode($i) ."&u=".urlencod e($u);

              echo("<a href=\"$PHP_SEL F?$urlquery\"> [$i] </a> ");
              }
              }
              break;
              case ( ($c >= 11) && ($c < ($num_pages - 5) ) ): //condition is met when the current pages is between page 10 and 5 pages prior to end of data
              $stop = $c + 5;

              for ($i= ($c - 4); $i <= $stop; $i++)
              {
              if($i == $c)
              {echo ($i." ");}
              else
              {
              $urlquery = "q=".urlencode( $q)."&ist=".url encode($ist)."& pt=".urlencode( $pt)."&b=".urle ncode($b)."&d=" .urlencode($d). "&k=".urlencode ($k)."&pr=".url encode($pr)."&o =".urlencode($o )."&s=".urlenco de($s)."&c=".ur lencode($i) ."&u=".urlencod e($u);

              echo("<a href=\"$PHP_SEL F?$urlquery\"> [$i] </a> ");
              }
              }
              break;
              case ( ($c >= 11) && ($c >= ($num_pages - 5) ) ): //condition is met when the current page is less than 5 pages away from end of data
              $stop = ($num_pages - c);

              for ($i= ($c - 5); $i <= $stop; $i++)
              {
              if($i == $c)
              {echo ($i." ");}
              else
              {
              $urlquery = "q=".urlencode( $q)."&ist=".url encode($ist)."& pt=".urlencode( $pt)."&b=".urle ncode($b)."&d=" .urlencode($d). "&k=".urlencode ($k)."&pr=".url encode($pr)."&o =".urlencode($o )."&s=".urlenco de($s)."&c=".ur lencode($i) ."&u=".urlencod e($u);

              echo("<a href=\"$PHP_SEL F?$urlquery\"> [$i] </a> ");
              }
              }
              break;
              }

              . If you have any questions about my script don't be shy with the questions. I don't mind helping other's out. I hope this helps.

              Comment

              Working...