This repository has been archived on 2025-01-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
luowei_exam/list_72_1_e.php
2025-01-09 11:57:41 +08:00

81 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<meta charset="UTF-8">
<?php
//数据列表 带编辑,新增与删除操作
//引入数据库配置文件
/*
* select * from student_1 limit 0,10
* select * from student_1 limit 10,10
*
*/
require_once "db_config.php";
mysqli_set_charset($link, 'utf8');
//取总记录数
$queryString="select count(name) as maxRows from user_70";
$rs=mysqli_query($link,$queryString);
$row=mysqli_fetch_assoc($rs);
$maxRows=$row['maxRows'];
$rowsOfPage = $_GET['rows_of_page'] ?? 15;
if(isset($_GET['action'])){
//翻页进入
if($_GET['action']=="top"){
$offset=0;
}
if($_GET['action']=="pre"){
$offset=$_GET['offset']-$rowsOfPage;
if($offset<0){
$offset=0;
}
}
if($_GET['action']=="next"){
$offset=$_GET['offset']+$rowsOfPage;
//处理最后一页的计算逻辑
if($offset>=$maxRows){
$offset=$_GET['offset'];
}
}
if($_GET['action']=='bottom'){
if($maxRows%$rowsOfPage==0){
//整页
$offset=$maxRows-$rowsOfPage;
}else{
//非整页
$offset=$maxRows-$maxRows%$rowsOfPage;
//20 10 20-10 25-25%10 20
}
}
}else{
//第一次进入偏移量为0
$offset=0;
}
$queryString="select * from user_70 limit $offset,$rowsOfPage";
$rs=mysqli_query($link,$queryString);
//用循环语句,从数据集中读出每一条记录
echo "<table border='1'>";
//id,name,password,gender,birthday,course,hometown,resume
echo "<tr><td colspan='10'>姓名列表</td>";
$pattern = '/(\d+)/';
while ($row=mysqli_fetch_assoc($rs)){
preg_match_all($pattern, $row['name'], $matches);
echo "<tr>";
echo "<td>".($matches[0][0]+1)."</td>";
echo "<td>".$row['name']."</td>";
}
echo "<tr><td colspan='10'>
<a href='list_72_1_e.php?action=top&offset=$offset&rows_of_page=$rowsOfPage'>首页</a>
|
<a href='list_72_1_e.php?action=pre&offset=$offset&rows_of_page=$rowsOfPage'>上一页</a>
|
<a href='list_72_1_e.php?action=next&offset=$offset&rows_of_page=$rowsOfPage'>下一页</a>
|
<a href='list_72_1_e.php?action=bottom&offset=$offset&rows_of_page=$rowsOfPage'>末页</a>
</td></tr>";
echo "</table>";