Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
composer require catfan/medoo
composer require league/plates
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<table>
<caption>用户信息表</caption>
<thead>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<?php foreach($users as $user):?>
<tr>
<td><?= $user['id']?></td>
<td><?= $user['uname']?></td>
<td><?= $user['gender']==1?'男':'女'?></td>
<td><button>删除</button><button>编辑</button></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php
//讨论省略点分页 前提: 两边的省略点都出现的时候
//分页条显示的页数
$showPages = 5;
//分页条的开始页码值
$startPage = 1;
//分页条的结束页码值
$endPage = $pages;
//分页条的终止页码相对于当前页码的偏移量:
$offset = ($showPages-1)/2;
if($showPages < $pages)
{
if($page > $offset+1)
{
$startOmit = '...';
$startPage = $page-$offset;
$endPage = $page+$offset;
if($endPage > $pages){$endPage=$pages;}
}else{
$startPage = 1;
$endPage = $showPages;
}
if($showPages<$pages && $page + $offset < $pages) $endOmit = '...';
}
?>
<!-- 动态生成分页条 跳转地址 当前页码的高亮显示 -->
<p>
<!-- 首页 上一页 下一页 尾页 -->
<!-- 获取上一页 -->
<?php $prev = $page-1; if($page == 1) $prev = 1; if($page != 1):?>
<a href="/page/1">首页</a>
<a href="//m.sbmmt.com/page/<?=$prev?>">上一页</a>
<?endif?>
<?php if(isset($startOmit)):?>
<a href="javascript:;"><?=$startOmit?></a><?endif?>
<?php
for ($i=$startPage; $i <=$endPage ; $i++) :
//生成动态的跳转地址 a href 属性 $jump
$jump = sprintf('/page/%d',$i);
$active = ($i==$page) ? 'active' : null;
?>
<a class="<?=$active?>" href="<?=$jump?>"><?=$i?></a>
<? endfor;?>
<?php if(isset($endOmit)):?>
<a href="javascript:;"><?=$endOmit?></a><?endif?>
<!-- 下一页 -->
<?php $next = $page+1; if($next == $pages) $next=$page; if($page != $pages) :?>
<a href="//m.sbmmt.com/page/<?=$next?>">下一页</a>
<a href="//m.sbmmt.com/page/<?=$pages?>">尾页</a>
<?endif?>
</p>
</body>
</html>