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表中的数据

首先创建表中的表头内容

在填入数据

最后的结果如下图:

相关推荐
杉氧1 小时前
状态管理变迁史:为什么我们放弃了 Redux 选择 Zustand?
android·前端·react native
三少爷的鞋4 小时前
别再靠 Code Review 守底线:我做了一个静态分析项目 RedLine
android
y = xⁿ13 小时前
DeepSeek Harness 学习日记:关于Agent接口,工具调用的底层实现
android·java·学习
2601_9620664915 小时前
【Sql Server】Update中的From语句,以及常见更新操作方式
android·java·数据库
用户693717500138420 小时前
曾经安卓开发人手一个的 EventBus,为什么现在没人爱用了?
android·android studio
九皇叔叔1 天前
MySQL ORDER BY 性能优化详解:Using filesort、联合索引、ASC/DESC 与覆盖索引
android·adb
OriginCoding1 天前
用 AI Agent 协作完成一个 Android TOTP 应用:从需求边界到 v1.0.0
android·ai编程
杉氧1 天前
React 灵魂:深入剖析 Hooks 与副作用(Side Effects)陷阱
android·前端·react native
又见情义1 天前
RK3568 + RTL8211F 网络唤醒(WOL)功能适配全记录
android·网络·驱动开发
用户0934077735141 天前
HarmonyOS WPS Open SDK 实践:registerApp 鉴权与就绪门禁
android·typescript·harmonyos