2020-04-09 22:22:04 +08:00

90 lines
3.0 KiB
PHP

<?php
$list_max_count = 5;
require_once 'config.php';
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
use MessageBoard\Database\DbMessage;
$db = new DbMessage();
$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>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header>
<h1>留言板</h1>
</header>
<div id="main">
<div class="func-btn">
<ul>
<li><a href="edit.php" class="btn">New</a></li>
</ul>
</div>
<section>
<!-- 主表格 -->
<div class="list-info">
<ul>
<li><?php echo $page.'/'.$max_page ?></li>
</ul>
</div>
<?php
if (count($list) > 0) {
echo '
<table>
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>updated_at</th>
<th>action</th>
</tr>
</thead>
<tbody>
';
foreach ($list as $key => $item) {
echo '
<tr>
<th>'.$item['id'].'</th>
<td>'.$item['title'].'</td>
<td>'.$item['updated_at'].'</td>
<td>
<ul>
<li><a href="edit.php?id='.$item['id'].'" class="btn">Edit</a></li>
<li><form action="save.php" method="post"><input type="hidden" name="id" value="'.$item['id'].'"><input type="hidden" name="delete" value="true"><input type="submit" class="btn" value="Delete"></form></li>
</ul>
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}
else {
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>
</html>