473,472 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

paging like google

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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Show Result Per Page
  3. $ResultPerPage=10;
  4. //Total Result Availaible
  5. $TotalResults =1000;
  6. //calculate how many pages will be created
  7. $TotalPages = $TotalResults / $ResultPerPage;
  8. $TotalPages = round($TotalPages,0);
  9. $c = 0;
  10. echo "<br>";
  11.  
  12. while($c<$TotalPages){
  13.  
  14. $page = $c + 1;
  15. if($_REQUEST['page']==$page){
  16. echo "[$page]";
  17. }
  18. else{
  19. echo "<a href=?page=$page>[$page] </a>";
  20. }
  21. $c = $c+1;
  22. }
  23. echo "<br>".$TotalResults." Pages in total".$TotalPages."<br>";
  24. ?>
  25.  
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
Jan 12 '07 #1
6 3624
b1randon
171 Recognized Expert New Member
can any one help me creating a dynamic pagination script for non-sql entries
i made this simple paging script

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Show Result Per Page
  3. $ResultPerPage=10;
  4. //Total Result Availaible
  5. $TotalResults =1000;
  6. //calculate how many pages will be created
  7. $TotalPages = $TotalResults / $ResultPerPage;
  8. $TotalPages = round($TotalPages,0);
  9. $c = 0;
  10. echo "<br>";
  11.  
  12. while($c<$TotalPages){
  13.  
  14. $page = $c + 1;
  15. if($_REQUEST['page']==$page){
  16. echo "[$page]";
  17. }
  18. else{
  19. echo "<a href=?page=$page>[$page] </a>";
  20. }
  21. $c = $c+1;
  22. }
  23. echo "<br>".$TotalResults." Pages in total".$TotalPages."<br>";
  24. ?>
  25.  
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<$TotalPages && $c<($start+10)){
$page = $c + 1;
if($_REQUEST['page']==$page){
echo "[$page]";
}
else{
echo "<a href=?page=$page>[$page] </a>";
}
$c = $c+1;
}
[/PHP]
That should do ya.
Jan 12 '07 #2
tejasonduty
1 New Member
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/
Feb 13 '07 #3
smdf
6 New Member
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.

[PHP]
$start = $c;
while($c<$TotalPages && $c<($start+10)){
$page = $c + 1;
if($_REQUEST['page']==$page){
echo "[$page]";
}
else{
echo "<a href=?page=$page>[$page] </a>";
}
$c = $c+1;
}
[/PHP]
That should do ya.
Feb 16 '07 #4
ronverdonk
4,258 Recognized Expert Specialist
smdf: you are not seriously 'suggesting' that b1randon re-writes his code for you!
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
Feb 16 '07 #5
smdf
6 New Member
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.

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
Feb 16 '07 #6
smdf
6 New Member
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=".urlencode($ist)."&pt=". urlencode($pt)."&b=".urlencode($b)."&d=".urlencode ($d)."&k=".urlencode($k)."&pr=".urlencode($pr)."&o =".urlencode($o)."&s=".urlencode($s)."&c=".urlenco de($i) ."&u=".urlencode($u);

echo("<a href=\"$PHP_SELF?$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=".urlencode($ist)."&pt=". urlencode($pt)."&b=".urlencode($b)."&d=".urlencode ($d)."&k=".urlencode($k)."&pr=".urlencode($pr)."&o =".urlencode($o)."&s=".urlencode($s)."&c=".urlenco de($i) ."&u=".urlencode($u);

echo("<a href=\"$PHP_SELF?$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=".urlencode($ist)."&pt=". urlencode($pt)."&b=".urlencode($b)."&d=".urlencode ($d)."&k=".urlencode($k)."&pr=".urlencode($pr)."&o =".urlencode($o)."&s=".urlencode($s)."&c=".urlenco de($i) ."&u=".urlencode($u);

echo("<a href=\"$PHP_SELF?$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.
Feb 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Navin | last post by:
HI, Guys There has been a lot of Ways to use paging in asp 1>Recordset approach -where whole records are pulled at client side... and then only the records which are needed are filtered.. and...
2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
1
by: Quentin Huo | last post by:
Hi, There is a page in my project which is just to list the all article titles by paging (20 titles per page). So I think it might be more efficient using SqlDataReader instead of DataSet. But...
3
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
7
by: underground | last post by:
I have a problem that I've spent countless hours on and I'm more than certain this is a obviuos issue to an expert but I am still learning. I have a paging script that I have modified to display a...
7
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla,...
6
by: ewolfman | last post by:
Hi, Recently we've hired professional SEO services to help up promote our website. They claim that pages which contain ASP.NET's Gridview with paging will not be scanned by the different spiders...
1
by: John Mott | last post by:
Hi All, I recently read a post that said that google and other spiders are unable to navigate paging in the GridView control because it uses postbacks and it can't determine the url. I've...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.