Blogger Information
Blog 14
fans 1
comment 0
visits 4553
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实现页面上一页,下一页功能并完成仿PHP中文网分页条
叫我孙大树
Original
338 people have browsed it
<?php
namespace _0819;
//引入朱老师的分页条函数
require __DIR__ . '/page_refer.php';
//加载模拟的数据库数据
$pure_userInfo = file_get_contents(__DIR__ . '/userinfo.json');
$pure_userInfo = json_decode($pure_userInfo, true);
//虚拟数据库
function VitrualSQLreturn($arr, $offset, $limit)
{
    return array_filter($arr, function ($e) use ($offset, $limit) {

        return $e['id'] > $offset && $e['id'] <= $offset + $limit;
    });
}

//实现GET传参翻页
$page = $_GET['page'] ?? (int)1;
$pageLimit = (int)20;
$userInfo = VitrualSQLreturn($pure_userInfo, ($page - 1) * $pageLimit, $pageLimit);
//实现分页器必要参数
$allDataCount = count($pure_userInfo);
$pageChange = createPages((int)$page, ceil((int)$allDataCount / (int)$pageLimit));
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>选手信息表</title>
    <style>
        table {
            /*width: 400px;*/
            border-collapse: collapse;
            text-align: center;
        }

        table th,
        table td {
            border: 1px solid;
            padding: 5px;
        }

        table thead {
            background-color: lightcyan;
        }

        table caption {
            font-size: larger;
            /*margin-bottom: 8px;*/
            font-weight: bold;
            border: 1px solid;
            padding: 5px 0px;
        }

        body > p {
            display: flex;
        }

        p > a {
            text-decoration: none;
            color: #555;
            border: 1px solid;
            padding: 5px 10px;
            margin: 10px 2px;
        }

        .active {
            background-color: seagreen;
            color: white;
            border: 1px solid seagreen;
        }

        .close{
            color: #bbb;
        }

    </style>
</head>
<body>
<table>
    <caption>选手信息表</caption>
    <thead>
    <tr>
        <th>id</th>
        <th>姓名</th>
        <th>身份证</th>
        <th>出生日期</th>
        <th>性别</th>
        <th>电话号</th>
        <th>住址</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($userInfo as $v) :extract($v) ?>
        <tr>
            <td><?= $id ?></td>
            <td><?= $name ?></td>
            <td><?= $identity_num ?></td>
            <td><?= $date_of_birth ?></td>
            <td><?php echo $sex ? '男' : '女' ?></td>
            <td><?= $phone_num ?></td>
            <td><?= $address ?></td>
        </tr>
    <?php endforeach ?>
    </tbody>
</table>
<p>
    <?php if ($page > 1) : ?>
    <a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $page-1 ?>" >上一页</a>
    <?php else: ?>
    <a class="close">上一页</a>
    <?php endif ?>
    <?php foreach ($pageChange as $v) : ?>
        <?php if (isset($v)): ?>
            <a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $v ?>" <?php echo $page == $v ? 'class="active"' : null ?>><?= $v ?></a>
        <?php else: ?>
            <a>......</a>
        <?php endif ?>
    <?php endforeach ?>
    <?php if ($page < ceil((int)$allDataCount / (int)$pageLimit)) : ?>
        <a href="<?php echo $_SERVER['PHP_SELF'] . '?page=' . $page+1 ?>" >下一页</a>
    <?php else: ?>
        <a class="close">下一页</a>
    <?php endif ?>
</p>
</body>
</html>
Correcting teacher:PHPzPHPz

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