按下一页无法翻页,按上一页直接跳回首页,不显示当前第几页
按下一页无法翻页,按上一页直接跳回首页,不显示当前第几页
pega.func.php里的代码
function showPage($page,$totalPage,$where=null,$sep=" "){
$where=($where==null)?null:"&".$where;
$url = $_SERVER ['PHP_SELF'];
$index = ($page == 1) ? "首页" : "<a href='{$url}?page=1{$where}'>首页</a>";
$last = ($page == $totalPage) ? "尾页" : "<a href='{$url}?page={$totalPage}{$where}'>尾页</a>";
$prevPage=($page>=1)?$page-1:1;
$nextPage=($page>=$totalPage)?$totalPage:$page+1;
$prev = ($page == 1) ? "上一页" : "<a href='{$url}?page={$prevPage}{$where}'>上一页</a>";
$next = ($page == $totalPage) ? "下一页" : "<a href='{$url}?page={$nextPage}{$where}'>下一页</a>";
$str = "总共{$totalPage}页/当前是第{$page}页";
for ($i = 1; $i <= $totalPage; $i++) {
//当前页无连接
if ($page == $i) {
$p .= "[{$i}]";
} else {
$p .= "<a href='{$url}?page={$i}'>[{$i}]</a>";
}
}
// echo "<hr/>";
$pageStr=$str.$sep . $index .$sep. $prev.$sep . $p.$sep . $next.$sep . $last;
return $pageStr;
}