分頁功能

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 <?php
$list_max_count = 5;
require_once 'config.php'; require_once 'config.php';
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php'; require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
use MessageBoard\Database\DbMessage; use MessageBoard\Database\DbMessage;
$db = new 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> <!DOCTYPE html>
@ -40,6 +31,11 @@ $list = $db->getList();
</div> </div>
<section> <section>
<!-- 主表格 --> <!-- 主表格 -->
<div class="list-info">
<ul>
<li><?php echo $page.'/'.$max_page ?></li>
</ul>
</div>
<?php <?php
if (count($list) > 0) { if (count($list) > 0) {
echo ' echo '
@ -80,6 +76,14 @@ $list = $db->getList();
echo '無資料'; 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> </section>
</div> </div>
</body> </body>