View Single Post
Old 11-27-2012, 06:57 AM   PM User | #5
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Hi, well hopefully this will make your life a whole lot easier. One of my scripts uses

http://developersbench.blogspot.com/...on-script.html (the download link is below the overview at the bottom)

But honestly although i like the way it does pagination data i did not like the output so what i do is i load the pagination data as normal,

then i grab those vars from the ps pagination script and did my own deal.

Im not saying you have to use ps pagination at all, its just what was in my script and i didnt want to rip it out so i just share the duty with my new way.

Here is the basic process so i hope it helps you. You can also set the range on either side of the current page.

first you do your normal query then you can see where i use the ps pagination to and where i xfer the values to my own deal.

It works perfectly for me.

PHP Code:

 $query
="did my query here";
 
$pager = new PS_Pagination($link,$query,$record_per_page,5);
 
$rs $pager->paginate();



//#############  added for page number display

// grab the values for my own page display code

$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 ******/

  // 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

      // show << link to go back to page 1

      
echo "<a href='{$_SERVER['PHP_SELF']}?page=1'>|&lsaquo;</a> ";

    }

    
// get previous page num   

    
$prevpage $curpg 1;   

    
// show < link to go back 1 page

    
echo "<a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>&lsaquo;</a> ";

  } 



  
// loop to show links to range of pages around current page

  // if previous page <, there is a space after it



  
for ($x $curpg $range

       
$x $curpg $range 1

       
$x++) {   

    
// if it's a valid page number (not < 1 or > last page)...  

    
if ($x && $x <= $maxpg) {      

      
// if we're on current page, not a link...      

      
if ($x == $curpg) { 

        
// 'highlight' it but don't make a link

        
echo "[<b>$x</b>] "

      } else { 

        
// if not current page, make it a link

        
echo "<a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> "

      }

    } 

  } 

  

  
// if not on last page, show forward > and last page >| links 

  
if ($curpg $maxpg) {   

    
// get next page   

    
$nextpage $curpg 1;    

    
// echo forward link for next page    

    
echo "<a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>&rsaquo;</a> ";

    
// echo forward link for lastpage, unless last page already showing

    
if ($curpg $range $maxpg) {

      echo 
" <a href='{$_SERVER['PHP_SELF']}?page=$maxpg'>&rsaquo;|</a>";

    }

  }

  
  
/****** end build pagination links ******/

// end pag_links() 
and then when you want to call the function on your page just do this



PHP Code:

<td colspan="4" align="center">
<?php
if(mysql_num_rows($rs)>0)
{
 
pag_links();

?>

</td>
Hope that helps ya..
durangod is offline   Reply With Quote
Users who have thanked durangod for this post:
mfoland (11-27-2012)