Blogger Information
Blog 23
fans 0
comment 1
visits 15987
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php基础实战-分页查询技巧及分页类的创建(2018年9月11日))
大白鲸的博客
Original
651 people have browsed it
  1. 分页查询

实例

<?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>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post