分页查询
实例
<?php //导入分页类 require 'inc/Page.php'; use model\Page; //实例化分页类 $page = new Page(); //连接数据库 $page->connect('mysql','localhost','oa_infomation','root','root'); //获取当前页 $currentPage = $page->getPage(); //获取总页数 $totalPages = $page->getPages('sb_info1'); //获取分页数据 $data = $page->getData('sb_info1'); ?> <!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"> <link rel="stylesheet" href="inc/bootstrap/css/bootstrap.min.css"> <title>Bootstrap分页查询</title> </head> <body> <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <!--表格展示数据--> <table class="table table-bordered table-hover text-center" style="width:1200px;"> <caption class="h3 text-center">员工信息表</caption> <tr class="info"> <td>ID</td> <td>类别</td> <td>类型</td> <td>品.牌</td> <td>规格型号</td> <td>处理器型号</td> <td>内存容量</td> </tr> <?php foreach ($data as $row): ?> <tr> <td><?php echo $row['ID']; ?></td> <td><?php echo $row['sb_class']; ?></td> <td><?php echo $row['sb_type']; ?></td> <td><?php echo $row['sb_made']; ?></td> <td><?php echo $row['sb_model']; ?></td> <td><?php echo $row['sb_cpu']; ?></td> <td><?php echo $row['sb_rom']; ?></td> </tr> <?php endforeach;?> </table> </div> </div> <div class="row"> <div class="col-md-8 col-md-offset-2 text-center"> <nav> <ul class="pagination"> <!-- 当前是第一页的时候,上一页和首页链接应该不显示--> <?php if($currentPage != 1): ?> <li><a href="demo6.php?p=1">首页</a></li> <li><a href="demo6.php?p=<?php echo $currentPage-1; ?>">«</a></li> <?php endif; ?> <?php for($i=1; $i<=$totalPages; $i++): ?> <!------高亮显示当前页码-----------> <li class="<?php if($currentPage==$i){echo 'active';}?>"> <a href="demo6.php?p=<?php echo $i ?>"> <?php echo $i ?> </a> </li> <?php endfor; ?> <!--当前已经是最后一页的时候,下一页和最后一页也应该不显示--> <?php if($currentPage != $totalPages) :?> <li><a href="demo6.php?p=<?php echo $currentPage+1; ?>">»</a></li> <li><a href="demo6.php?p=<?php echo $totalPages; ?>">尾页</a></li> <?php endif; ?> </ul> </nav> </div> </div> </div> <script src="inc/jquery/jquery.js"></script> <script src="inc/bootstrap/js/bootstrap.min.js"></script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例