Advertisement
Guest User

Simple PHP Pagination Function

a guest
Dec 7th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. Usage: doPagination($totalrows,$p,$numofp);
  2. $totalrows = The total number of rows returned by the query
  3. $p = The current page, default would be 1
  4. $numofp = The total number of pages (this will depend on the total rows and limit)
  5.  
  6. function doPagination($totalrows,$p=1,$numofp)
  7. { ?>
  8. <div class="pagination"><ul><li><a href="?" title="reload"><?=$totalrows?> Record<?php if($totalrows>1) {?>s<?php } ?></a></li>  
  9. <?php if($p>2) { ?> <li><a href="<?=PHPSELF?>?" title="first">&laquo; &laquo;</a></li> <?php } ?>
  10. <?php if($p>1) { ?> <li><a href="<?=PHPSELF?>?p=<?=$p-1?>" title="previous">&laquo;</a></li> <?php } ?>
  11. <?php for($i = $p; $i <= $p+LIMIT; $i++) { if($i == $p) { ?> <li class="active"><a href="#"><?=$i?></a></li> <?php } else { if($i<$numofp) { ?> <li><a href="<?=PHPSELF?>?p=<?=$i?>"><?=$i?></a></li> <?php } } } ?>
  12. <?php if($p<$numofp) { ?> <li><a href="<?=PHPSELF?>?p=<?=$p+1?>" title="next">&raquo;</a></li> <?php } ?>
  13. <?php if($p<$numofp) { ?> <li><a href="<?=PHPSELF?>?p=<?=$numofp?>" title="last">&raquo; &raquo;</a></li> <?php } ?>
  14. </ul></div>
  15. <?php }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement