Correction status:qualified
Teacher's comments:
<?php require 'model/page.php'; use model\Page; $obj= new Page(3); $obj->connect('mysql','127.0.0.1','php','root',''); $total_page=$obj->getPage('student'); $res=$obj->getData('student'); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> table ,tr ,th ,td {border: 1px black solid;} td{padding: 5px auto;} table{border-collapse: collapse; margin: auto;text-align: center;width: 60%;} table tr:first-child{background: #1b6d85;} caption{margin:15px auto;font-size: 1.5em;} div{text-align: center;} p,form{display: inline-block;} a{text-decoration-line: none;} a:hover{text-decoration-line: underline;} </style> </head> <body> <table> <caption>My Student</caption> <tr> <th>id</th> <th>名字</th> <th>性别</th> <th>年纪</th> <th>班级</th> </tr> <?php foreach ($res as $current): ?> <tr> <td> <?php echo $current['id'] ?></td> <td> <?php echo $current['name'] ?></td> <td> <?php echo $current['gender'] ?></td> <td> <?php echo $current['age'] ?></td> <td> <?php echo $current['class'] ?></td> </tr> <?php endforeach; ?> </table> <div> <p> <a href="http://localhost/phpstudy/0910/demo2.php?p=1">首页</a> <a href="http://localhost/phpstudy/0910/demo2.php?p=<?php echo ($obj->page==1)?1:($obj->page-1) ?>">上一页</a> <?php for ($i=1;$i<=$total_page;$i++): ?> <a href="http://localhost/phpstudy/0910/demo2.php?p=<?php echo $i ?>" <?php if($obj->page==$i) echo 'style="background:black;color:white;"' ?>><?php echo $i;?></a> <?php endfor;?> <a href="http://localhost/phpstudy/0910/demo2.php?p=<?php echo ($obj->page==$total_page)?$total_page:($obj->page+1) ?>">下一页</a> <a href="http://localhost/phpstudy/0910/demo2.php?p=<?php echo $total_page; ?>">末页</a> </p> <form action="" method="get"> 第 <select name="p"> <?php for($i=1;$i<=$total_page;$i++): ?> <option <?php if($i==$obj->page) echo "selected"?> > <?php echo $i; ?> </option> <?php endfor; ?> </select> 页 <input type="submit" value="跳转" name="submit"> </form> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例
offset 偏移量=(当前页-1)*每页显示数量。