PHP: Simple pagination uses a Twitter Bootstrap layout:
- $targetpage = "search.php";
- $limit = 50; //Records per page
- $total_pages = $total_count; //Total number of the records to paginate
- $stages = 3;
- $page = mysql_escape_string($_REQUEST['page']);
- if ($page) {
- $start = ($page - 1) * $limit;
- } else {
- $start = 0;
- }
- if ($page == 0) {
- $page = 1;
- }
- $prev = $page - 1;
- $next = $page + 1;
- $lastpage = ceil($total_pages / $limit);
- $LastPagem1 = $lastpage - 1;
- $paginate = '';
- if ($lastpage > 1) {
- $paginate .= "<div class='pagination pagination-centered'><ul>";
- if ($page > 1) {
- $paginate.= "<li><a href='#' onclick='showpage($prev);'>«</a></li>";
- } else {
- $paginate.= "<li class='disabled'><span>«</span></li>";
- }
- if ($lastpage < 7 + ($stages * 2)) {
- for ($counter = 1; $counter <= $lastpage; $counter++) {
- if ($counter == $page) {
- $paginate.= "<li class='active'><span>$counter</span></li>";
- } else {
- $paginate.= "<li><a href='#' onclick='showpage($counter);'>$counter</a></li>";
- }
- }
- } elseif ($lastpage > 5 + ($stages * 2)) {
- if ($page < 1 + ($stages * 2)) {
- for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) {
- if ($counter == $page) {
- $paginate.= "<li class='active'><span>$counter</span></li>";
- } else {
- $paginate.= "<li><a href='#' onclick='showpage($counter);'>$counter</a></li>";
- }
- }
- $paginate.= "<li class='disabled'><span>...</span></li>";
- $paginate.= "<li><a href='#' onclick='showpage($LastPagem1);'>$LastPagem1</a></li>";
- $paginate.= "<li><a href='#' onclick='showpage($lastpage);'>$lastpage</a></li>";
- } elseif ($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) {
- $paginate.= "<li><a href='#' onclick='showpage(1);'>1</a></li>";
- $paginate.= "<li><a href='#' onclick='showpage(2);'>2</a></li>";
- $paginate.= "<li class='disabled'><span>...</span></li>";
- for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) {
- if ($counter == $page) {
- $paginate.= "<li class='active'><span>$counter</span></li>";
- } else {
- $paginate.= "<li><a href='#' onclick='showpage($counter);'>$counter</a><li>";
- }
- }
- $paginate.= "<li class='disabled'><span>...</span></li>";
- $paginate.= "<li><a href='#' onclick='showpage($LastPagem1);'>$LastPagem1</a></li>";
- $paginate.= "<li><a href='#' onclick='showpage($lastpage);'>$lastpage</a></li>";
- } else {
- $paginate.= "<li><a href='#' onclick='showpage(1);'>1</a></li>";
- $paginate.= "<li><a href='#' onclick='showpage(2);'>2</a></li>";
- $paginate.= "<li class='disabled'><span>...</span></li>";
- for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) {
- if ($counter == $page) {
- $paginate.= "<li class='active'><span>$counter</span></li>";
- } else {
- $paginate.= "<li><a href='#' onclick='showpage($counter);'>$counter</a></li>";
- }
- }
- }
- }
- if ($page < $counter - 1) {
- $paginate.= "<li><a href='#' onclick='showpage($next);'>»</a></li>";
- } else {
- $paginate.= "<li class='disabled'><span>»</span></li>";
- }
- $paginate.= "</ul></div>";
- }
- echo $paginate;
Комментариев нет:
Отправить комментарий