added pagination for admin page

This commit is contained in:
printempw 2016-03-06 14:12:12 +08:00
parent 314214de10
commit b0ad3fa412
3 changed files with 91 additions and 7 deletions

View File

@ -2,8 +2,8 @@
/**
* @Author: prpr
* @Date: 2016-02-03 14:39:50
* @Last Modified by: prpr
* @Last Modified time: 2016-02-10 15:05:08
* @Last Modified by: printempw
* @Last Modified time: 2016-03-06 14:07:38
*/
require "../includes/session.inc.php";
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
@ -55,8 +55,10 @@ if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是
<tbody>
<?php
$page_now = isset($_GET['page']) ? $_GET['page'] : 1;
$db = new Database();
$result = $db->query("SELECT * FROM users");
$result = $db->query("SELECT * FROM users ORDER BY `uid` LIMIT ".(string)(($page_now-1)*30).", 30");
$page_total = $db->getRecordNum()/30;
while ($row = $result->fetch_array()) { ?>
<tr>
<td><?php echo $row['uid']; ?></td>
@ -80,6 +82,39 @@ if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是
<?php } ?>
</tbody>
</table>
<ul class="pagination">
<?php if ($page_now == 1): ?>
<li class="disabled">
<a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
</li>
<?php else: ?>
<li>
<a href="index.php?page=<?php echo $page_now-1; ?>" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<?php endif;
for ($i = 1; $i <= $page_total; $i++) {
if ($i == $page_now) {
echo '<li class="active"><a href="#">'.(string)$i.'</a></li>';
} else {
echo '<li><a href="index.php?page='.$i.'">'.(string)$i.'</a></li>';
}
}
if ($page_now == $page_total): ?>
<li class="disabled">
<a href="#" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
</li>
<?php else: ?>
<li>
<a href="index.php?page=<?php echo $page_now+1; ?>" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
<?php endif; ?>
</ul>
</div>
</body>

View File

@ -1,8 +1,8 @@
/*
* @Author: prpr
* @Date: 2016-02-04 16:47:54
* @Last Modified by: prpr
* @Last Modified time: 2016-02-04 16:48:04
* @Last Modified by: printempw
* @Last Modified time: 2016-03-06 14:11:26
*/
.pure-table {
margin: 80px auto 0;
@ -24,3 +24,47 @@ input {
.fw {
width: 100%;
}
.pagination {
display: inline-block;
padding-left: 0;
margin: 20px 0;
border-radius: 4px;
}
.pagination > li {
display: inline;
}
.pagination > li:first-child > a, .pagination > li:first-child > span {
margin-left: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.pagination > li > a, .pagination > li > span {
position: relative;
float: left;
padding: 6px 12px;
margin-left: -1px;
line-height: 1.42857143;
color: #337ab7;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
}
.pagination > li > a:focus, .pagination > li > a:hover {
z-index: 3;
color: #fff;
background-color: #337ab7;
border-color: #337ab7;
}
.pagination > .active > a, .pagination > .active > a:focus, .pagination > .active > a:hover {
z-index: 3;
color: #fff;
cursor: default;
background-color: #337ab7;
border-color: #337ab7;
}
.pagination > .disabled > a, .pagination > .disabled > a:focus, .pagination > .disabled > a:hover {
color: #777;
cursor: not-allowed;
background-color: #fff;
border-color: #ddd;
}

View File

@ -2,8 +2,8 @@
/**
* @Author: printempw
* @Date: 2016-02-02 21:59:06
* @Last Modified by: prpr
* @Last Modified time: 2016-02-06 23:06:30
* @Last Modified by: printempw
* @Last Modified time: 2016-03-06 13:41:24
*/
class Database
@ -60,6 +60,11 @@ class Database
return $this->query($sql)->num_rows;
}
public function getRecordNum() {
$sql = "SELECT * FROM users WHERE 1";
return $this->query($sql)->num_rows;
}
public function checkRecordExist($key, $value) {
return ($this->getNumRows($key, $value) != 0) ? true : false;
}