Notice: Undefined variable: p in D:\phpnow\vhosts\127.0.0.39\lib\page.func.php on line 39 总共是4;页/当前是第4页首页 上一页 [1][2][3] 尾页
Notice: Undefined variable: p in D:\phpnow\vhosts\127.0.0.39\lib\page.func.php on line 39
总共是4;页/当前是第4页首页 上一页 [1][2][3] 尾页
<?php require_once'../include.php'; $sql="select * from imooc_admin"; $totalRows=getResultNum($sql); //echo $totalRows; $pageSize=2; //得到总页数 $totalPage=ceil($totalRows/$pageSize); $page=$_REQUEST['page']?(int)$_REQUEST['page']:1; //echo $page; if($page<1||$page==null||!is_numeric($page)){ $page=1; } if($page>$totalPage)$page==$totalPage; $offset=($page-1)*$pageSize; $sql="select * from imooc_admin limit $offset,$pageSize"; $rows=fetchAll($sql); //print_r ($rows); foreach($rows as $row) { echo "<br/>"; echo $row['id']; } echo showPage($page,$totalPage); function showPage($page,$totalPage,$where=null,$sep=" "){ $where=($where==null)?null:"&".$where; $url=$_SERVER['PHP_SELF']; $index=($page==1)?"首页":"<a href='{$url}?page=1'>首页</a>"; $last=($page==$totalPage)?"尾页": "<a href='{$url}?page=$totalPage'>尾页</a>" ; $prev=($page==1)? "" :"<a href='{$url}?page=". ($page-1). "'>上一页</a>"; $next=($page==$totalPage)? "" : "<a href='{$url}?page=".($page+1) . " '>下一页</a>" ; $str="总共是$totalPage;页/当前是第{$page}页"; for($i=1;$i<$totalPage;$i++){ //当前页无连接 if($page==$i){ $p.="[{$i}]"; }else{ $p.="<a href='{$url}?page={$i}'>[{$i}]</a>"; } } $pageStr=$str.$index.$sep.$prev.$sep.$p.$sep.$next.$sep.$last; return $pageStr; }