PHP分页显示数据,在phpMyadmin中添加数据

<?php

$con=mysqli_connect('localhost','root','','stu');

mysqli_query($con,"set names utf8"); //设置字符集为utf8

$sql="select * from teacher";

result=mysqli_query(con,$sql);

count=mysqli_num_rows(result); //记录总条数$count。

pagesize=10;//每页要显示的记录条数pagesize

if (count%pagesize==0) pagecount=count/pagesize;else pagecount=(int)(count/pagesize+1); //总页数$pagecount

row=mysqli_fetch_assoc(result); //数组$row的键名为字段名

page=@_REQUEST["page"]; //欲显示的页数$page

if (page==null) currentpage=1;else currentpage=intval(page);

for(i=1;i<=(currentpage-1)\*pagesize;$i++) //指定每一页面显示20条记录

{ if (!$row) break;

row=mysqli_fetch_assoc(result);

}

?>

<table width="500" border="1" align="center" cellpadding="0">

<tr>

<td height="25" colspan="5" align="center" bgcolor="#99CCCC">第<?php echo currentpage;?\>页/共\pagecount;?>页</font> &nbsp;&nbsp;

<?php

if ($currentpage==1) echo "首 页 | 上一页 | ";

else

{?>

<a href="EX7-7.php?page=1">首 页</a> |

<a href="EX7-7.php?page=<?php echo $currentpage-1;?>">上一页</a> |

<?php

}

if (currentpage==pagecount) echo "下一页 | 尾 页";

else

{?>

<a href="EX7-7.php?page=<?php echo $currentpage+1;?>">下一页</a> |

<a href="EX7-7.php?page=<?php echo $pagecount;?>">尾 页</a>

<?php

}

?></td>

</tr>

<tr>

<td width="100" height="25" align="center">职工号</td>

<td width="100" height="25" align="center">姓名</td>

<td width="100" height="25" align="center">密码</td>

<td width="100" height="25" align="center">性别</td>

<td width="100" height="25" align="center">出生日期</td>

</tr>

<?php

for(i=1;i<=pagesize;i++)

{ if (!$row) break;

?>

<tr>

<td width="100" height="25" align="center"><?php echo $row["职工号"];?></td>

<td width="100" height="25" align="center"><?php echo $row["姓名"];?></td>

<td width="100" height="25" align="center"><?php echo $row["密码"];?></td>

<td width="100" height="25" align="center"><?php echo $row["性别"];?></td>

<td width="100" height="25" align="center"><?php echo $row["出生日期"];?></td>

</tr>

<?php

row=mysqli_fetch_assoc(result);

}

?>

</table>

添加teacher表中的数据

首先创建表中的表头内容

在填入数据

最后的结果如下图:

相关推荐
czhc11400756637 分钟前
JAVA1027抽象类;抽象类继承
android·java·开发语言
_Sem1 小时前
KMP实战:从单端到跨平台的完整迁移指南
android·前端·app
從南走到北1 小时前
JAVA国际版任务悬赏发布接单系统源码支持IOS+Android+H5
android·java·ios·微信·微信小程序·小程序
vistaup1 小时前
Android ContentProvier
android·数据库
我是场1 小时前
Android Camera 从应用到硬件之- 枚举Camera - 1
android
4Forsee1 小时前
【Android】View 事件分发机制与源码解析
android·java·前端
咕噜签名分发冰淇淋1 小时前
苹果ios安卓apk应用APP文件怎么修改手机APP显示的名称
android·ios·智能手机
应用市场1 小时前
从零开始打造Android桌面Launcher应用:原理剖析与完整实现
android
叶羽西1 小时前
Android15增强型视觉系统(EVS)
android
沅霖1 小时前
android kotlin语言中的协程
android·开发语言·kotlin