分頁功能

This commit is contained in:
Yuan Chiu 2020-04-09 22:22:04 +08:00
parent 55f10909b4
commit 11b00e484b

View File

@ -1,24 +1,15 @@
<?php
$list_max_count = 5;
require_once 'config.php';
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
use MessageBoard\Database\DbMessage;
$db = new DbMessage();
$list = $db->getList();
// $list = [
// [
// 'id' => 1,
// 'title' => 'text',
// 'updated_at' => '2020-04-01 12:13',
// ],
// [
// 'id' => 2,
// 'title' => 'text',
// 'updated_at' => '2020-04-01 12:13',
// ],
// ];
$page = !empty($_GET["p"])?$_GET["p"]:1;
$max_count = $db->getCount();
$max_page = ceil($max_count/$list_max_count);
$list = $db->getList($page, $list_max_count);
?>
<!DOCTYPE html>
@ -40,6 +31,11 @@ $list = $db->getList();
</div>
<section>
<!-- 主表格 -->
<div class="list-info">
<ul>
<li><?php echo $page.'/'.$max_page ?></li>
</ul>
</div>
<?php
if (count($list) > 0) {
echo '
@ -80,6 +76,14 @@ $list = $db->getList();
echo '無資料';
}
?>
<div class="table-func">
<ul>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'].'?p='.'1'; ?>">|&lt;</a></li>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'].'?p='.(($page-1)>0?($page-1):1); ?>">&lt;</a></li>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'].'?p='.(($page+1)<$max_page?($page+1):$max_page); ?>">&gt;</a></li>
<li><a href="<?php echo $_SERVER['SCRIPT_NAME'].'?p='.$max_page; ?>">&gt;|</a></li>
</ul>
</div>
</section>
</div>
</body>