PHP分页函数代码(简单实用型)

2019-04-09 13:00:08于丽

$page_start = $page_current - 4;
$page_end = $page_current + 4;
if ($page_current < 5) {
$page_start = 1;
$page_end = 5;
}
if ($page_current > $page_count - 4) {
$page_start = $page_count - 8;
$page_end = $page_count;
}
if ($page_start < 1)
$page_start = 1;
if ($page_end > $page_count)
$page_end = $page_count;
$pagebar = "";
$sql = "select * from cms_ask where ansower <> ' ' order by id desc limit " . (($page_current - 1) * $page_size) . "," . $page_size;
$row=$this -> user -> getall("$sql");
foreach($row as $v){
echo '<dl><dt>问:'.$v["question"].'</dt><dd>答:'.$v["ansower"].date("Y-m-d H:i:s",$v["postTime"]).'</dd></dl>';

}

$pagebar .= "<div class="page">";
$pagebar .= "<ol>";
if ($page_current != 1) {
$pagebar .= '<li><a href="javascript:get_comment(1)" class="sx">FIRST</a></li>';
}
for ($i = $page_start; $i <= $page_end; $i++) {
if ($i == $page_current) {
$pagebar .= "<li><span class="sort">" . $i . "</span></li>";
} else {
$pagebar .= "<li><a href='javascript:get_comment(" . $i . ")'>" . $i . "</a></li>";
}
}

if ($page_current != $page_count) {
$pagebar .= "<li><a href='javascript:get_comment(" . $page_count . ")' class='sx'>END</a></li>";
}
$pagebar .= "</ol>";
$pagebar .= " </div>";
echo $pagebar;
}
相关文章 大家在看