2020-04-10 16:25:35 +08:00

160 lines
4.7 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"])?(int)$_GET["p"]:1;
$max_count = !empty($_GET['rowcount']) ? (int)$_GET['rowcount'] : $db->getCount();
$max_page = ceil($max_count/$list_max_count);
$list = $db->getList($page, $list_max_count);
// $db->query("SELECT SQL_CALC_FOUND_ROWS * FROM xxx WHERE name='abc' LIMIT 100,10");
// $max_count = $db->getOne("SELECT FOUND_ROWS()");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/general.css">
<title>Document</title>
<style>
section, div.func-btn {
margin: 0 auto;
width: 800px;
}
table {
width: 100%;
table-layout: auto;
border-collapse: collapse;
}
table thead th{
border-bottom: 2px gray solid;
padding: 0;
}
table tbody th, table tbody td {
border-bottom: 1px gray solid;
padding: 0;
}
table>tbody th:nth-child(1) {
width: 3em;
}
table>tbody td:nth-child(2) {
/* width: 100%; */
text-align: center;
}
table>tbody td:nth-last-child(2) {
width: 12em;
text-align: center;
}
table>tbody td:nth-last-child(1) {
width: 11em;
text-align: center;
}
.table-row-func ul {
padding-left: 0em;
}
div.table-func {
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<header>
<h1>留言板</h1>
</header>
<div id="main">
<div class="func-btn">
<ul>
<li><a href="edit.php" class="btn green">New</a></li>
</ul>
</div>
<section>
<!-- 主表格 -->
<?php
if (!empty($list) && count($list) > 0) {
?>
<table>
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>updated_at</th>
<th>action</th>
</tr>
</thead>
<tbody>
<?php } ?>
<?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><a href="view.php?id='.$item['id'].'">'.$item['title'].'</a></td>
<td>'.$item['updated_at'].'</td>
<td class="table-row-func">
<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 red" 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><?php echo $page.'/'.$max_page ?></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>
</div>
</body>
</html>