欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP通用分页

程序员文章站 2022-04-25 23:24:35
...
php通用分页,先看下样式

代码如下:

 0 ? intval($page) : 1;$conn = mysql_connect("127.0.0.1","root","") or die('连接数据库失败');mysql_select_db("demo",$conn);mysql_query("SET NAMES UTF8");$pageSize = 10;//每页显示的数据$showPage = 5;//显示页码$sql = "select * from demo limit ".($page-1)*$pageSize.",".$pageSize;$result = mysql_query($sql,$conn);echo '
';echo '';while($row = mysql_fetch_assoc($result)){ echo ''; echo ''; echo ''; echo '';}echo '
ID NAME
'.$row['id'].''.$row['name'].'
';mysql_free_result($result);$total_sql = "select count(*) from demo";$total_result = mysql_fetch_array(mysql_query($total_sql));$total = $total_result[0];//计算总页数$total_page = ceil($total/$pageSize);mysql_close($conn);/*分页条*/$page_banner = '';echo $page_banner;
相关标签: PHP通用分页