I have been using this for years, problem is, I get a million page links
at the bottom, I have been trying to add stages like 123...789 but cannot
get it to work. I did find another pagination script that does
that but I would rather stay with this one if possible. anyone see a quick edit
not requiring a rewrite or anything complex.
PHP Code:
//-------------------------------TOP OF PAGE
$limit=mysql_real_escape_string($_GET[limit]);//clean
$page=mysql_real_escape_string($_GET[page]);//clean
$query=mysql_real_escape_string($_GET[query]);//clean
if (!($limit)){
$limit = 50;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
if ($numrows % $limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//--------------------------- END TOP OF PAGE
// Doing whatever this pageination is for.....
//----------------------------BOTTOM OF PAGE
// Bottom code of pagination
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"search.php?query=$query&page=$back_page&limit=$limit\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"search.php?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"search.php?query=$query&page=$next_page&limit=$limit\">next</a>");}
//------------------------END BOTTOM OF PAGE
here is one that i have used for awhile, it was done for me as a favor by a very experience coder awhile back
have used it alot and it works great
its pretty simple and it also does what you say,
and it allows you to set the range on either side of the page you are on.
i use ps pagination and it does a query and then load the value in $rs
and then i just copy the vars from that result from the pagination array into my little script
basically i changed from using the pagination display output to my own thats why i copied the results from the array here
here ya go, maybe if you look at this it will give you some hints bud.
hope it helps.
PHP Code:
//also the record_per_page is set up here as well before the query
// the query is done up before this
$pager = new PS_Pagination($link,$query,$record_per_page,5);
$rs = $pager->paginate();
//############# added for page number display
// i take what need from the pager array
$maxpg = $pager->max_pages;
$curpg = $pager->page;
$rppg = $pager->rows_per_page;
$off_setpg = $pager->offset;
function pag_links() {
global $curpg, $maxpg;
/****** build the pagination links ******/
// i believe this is the part your looking for
// range of num links to show on either side of current page
$range = 5;
// show $range pages on either side of current page. if this includes page
// 1, don't show "First". if this includes last page, don't show "Last"
// show back links |< and < unless at page 1
if ($curpg > 1) {
if ($curpg - $range > 1) { // wouldn't show page 1 in range
Thanks I will try it, I scraped that code above I posted
its a shame because it worked great but left a ton of page
links that grow after a a while. I Posted that here because I
thought it might be a line or two edit but see it is too complex
to save.
I did visit the site I found it at, http://www.evolt.org/node/19340
and read the old comments and did see some edits to manage all
those page links, but none work I tried them, on page 1 and 2,
they leave out next links and cause bad links.
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b>\n");} // If current page don't give link, just text. else{ echo("<a href=\"search.php?query=$query&page=$ppage&limit=$limit\">$i</a> \n");} }
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo(" <a href=\"search.php?query=$query&page=$next_page&limit=$limit\">next</a>");} //------------------------END BOTTOM OF PAGE
Check out this modification:
PHP Code:
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b>\n");} // If current page don't give link, just text. else{ echo("<a href=\"search.php?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
//Change if($i>$page+10){ $i+99; //Adds 99 to $i hence from page 10, the pages skip by 100 //Because there is another 1 being added at the for loop //Change 99 to whatever interval you want }
//Change ends here }
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link. $next_page = $page + $limit; echo(" <a href=\"search.php?query=$query&page=$next_page&limit=$limit\">next</a>");} //------------------------END BOTTOM OF PAGE
It would be great if I could have stages like 3
(three links before current page and three links after) or something
like that, it would be nice to never have more then 15 links
at the bottom.
I'm glad you posted I wanted to keep this. I had it for a long time.
Thanks
Sonny
PS I implemented your edit, but I only had 24 pages and it showed 24 links
It would be great if I could have stages like 3
(three links before current page and three links after) or something
like that, it would be nice to never have more then 15 links
at the bottom.
I'm glad you posted I wanted to keep this. I had it for a long time.
Thanks
Sonny
PS I implemented your edit, but I only had 24 pages and it showed 24 links
Sorry, I had used the wrong comparison for $i. Check the below code out.
PHP Code:
if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"search.php?query=$query&page=$back_page&limit=$limit\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b>\n");} // If current page don't give link, just text. else{ echo("<a href=\"search.php?query=$query&page=$ppage&limit=$limit\">$i</a> \n");
//Change if($i>3){
$i+9; //Adds 9 to $i hence from page 3, the pages skip by 10 //Because there is another 1 being added at the for loop //Change 9 to whatever interval you want }
//Change ends here
} }
__________________
For professional Hosting and Web design.....