PHP 分页代码
两个分页代码,用第一个
第一个分页代码
/** * $page = (!$_GET['page']) ? 1 : intval($_GET['page']); * $page_size = 20; * 上面两行是在需要的分页的页面上边调用 * * @param int $num 总页数 * @param int $page_size 每页显示条数 * @param int $page 当前页 * @param int $shift 当前页两边的偏移数 * @param stting $page_var $_GET val * */ function page($num, $page_size, $page, $shift, $page_var = '') { $url = $_SERVER["REQUEST_URI"]; $url = parse_url($url); $url = $url['path']; $page_num = ceil($num / $page_size); //一共有多少页 $page_start = $page - $shift; //当前page加5 $page_end = $page + $shift; //当前page减5 if ($page_start < 1) { $page_end = $page_end + (1 - $page_start); //公式得出$this -> page_i为负数时 页面总数是11 $page_start = 1; } if ($page_end > $page_num) { $page_start = $page_start - ($page_end - $page_num); $page_end = $page_num; if ($page_start < 1) $page_start = 1; } // return $page_end; $page_up = $page -1; //上一页 $page_next = $page +1; //下一页 //$str .= '<div class="PageList">'; if ($page != 1) { $str .= '<a href="' . $url . '?page=' . $page_up . $page_var . '"><</a>'; $str .= '<a href="' . $url . '?page=1' . $page_var . '">1...</a>'; } for ($page_for_i = $page_start; $page_for_i <= $page_end; $page_for_i++) { if ($page == $page_for_i) { $str .= '<span class="PageEllipsis">' . $page_for_i . '</span>'; } else { $str .= "<a href=\"" . $url . "?page=" . $page_for_i . $page_var . "\" title=\"第" . $page_for_i . "页\">" . $page_for_i . "</a>"; //$str .= $page_for_i."</a>"; } } if ($page != $page_num) { $str .= '<a href="' . $url . '?page=' . $page_num . $page_var . '">...'.$page_num.'</a>'; $str .= '<a href="' . $url . '?page=' . $page_next . $page_var . '">></a>'; } //$str .= '</div>'; return $str = ($page_num < 2) ? '共' . $num . '条记录' : $str; }
第二个分页代码
function page_html($num, $page_size, $page, $url, $shift, $page_var = '') { $page_num = ceil($num / $page_size); //一共有多少页 $page_start = $page - $shift; //当前page加5 $page_end = $page + $shift; //当前page减5 if ($page_start < 1) { $page_end = $page_end + (1 - $page_start); //公式得出$this -> page_i为负数时 页面总数是11 $page_start = 1; } if ($page_end > $page_num) { $page_start = $page_start - ($page_end - $page_num); $page_end = $page_num; if ($page_start < 1) $page_start = 1; } // return $page_end; $page_up = $page -1; //上一页 $page_next = $page +1; //下一页 //$str .= '<div class="PageList">'; if ($page != 1) { $str .= '<a href="' . $url . '_' . $page_up . $page_var . '.html">上一页</a>'; } for ($page_for_i = $page_start; $page_for_i <= $page_end; $page_for_i++) { if ($page == $page_for_i) { $str .= '<span class="PageEllipsis">' . $page_for_i . '</span>'; } else { $str .= "<a href=\"" . $url . "_" . $page_for_i . $page_var . ".html\" title=\"第" . $page_for_i . "页\">" . $page_for_i . "</a>"; //$str .= $page_for_i."</a>"; } } if ($page != $page_num) { $str .= '<a href="' . $url . '_' . $page_next . $page_var . '.html">下一页</a>'; } return $str = ($page_num < 2) ? '共' . $num . '条记录' : $str; }
Leave a comment
0 Comments.