Paging your content dynamicly
Do you need a function for paging your content? Feel free to use this php code for your application.
If you know any tips to improve let me know.
- function paging($m, $u, $p) {
- if ($m > 1) {
- if ($p == "") $p = 1;
- for ($i=$p-$u; $i<=$p+$u; $i++) {
- if ($i == $p-$u) {
- if ($p == 1) $strResult .= '1 ';
- else $strResult .= '<a href="?p=1" class="p">1</a> ';
- if ($p-$u > 2) $strResult .= '... ';
- }
- if ($i < $m && $i != 1 && $i > 0) {
- if ($i == $p) $strResult .= $i.' ';
- else $strResult .= '<a href="?p='.$i.'" class="p">'.$i.'</a> ';
- }
- if ($i == $p+$u) {
- if ($i < $m-1) $strResult .= ' ... ';
- if ($p == $m) $strResult .= $m.' ';
- else $strResult .= '<a href="?p='.$m.'" class="p">'.$m.'</a>';
- }
- }
- }
- return $strResult;
- }
Download the code here.
Example:





