1. 程式人生 > >第106講 僱員管理系統④-model1模式僱員分頁

第106講 僱員管理系統④-model1模式僱員分頁

工程儲存路徑
密碼:gixq
image

image

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>
僱員資訊列表</title> </head> <h1>僱員資訊列表</h1> <?php include 'Constant.php'; $pageNow = 1; // 當前頁數 $rowcount = 0; // 資料庫總行數 $pageSize = 10; // 每頁size $pageCount = 0; // 總頁數 if (! empty($_GET['page'])) { $pageNow = $_GET['page']; } $mysqli = new mysqli(localhost, hostname, password, dbname); if
($mysqli->connect_error) { echo "資料庫連接出錯" . $mysqli->connect_error; exit(); } $sqlCount = "select * from emp"; $resResult = $mysqli->query($sqlCount); $rowcount = $resResult->num_rows; // 我去 這個取出rowcount為啥出問題 為啥不能用select count(*) from emp;執行取出 數組裡邊顯示有值啊 為啥走$resResult->assoc()[0] 出錯呢
// echo "<br/>rowCount " . $rowcount; $pageCount = ceil($rowcount / $pageSize); // echo "<br/>總頁數 " . $pageCount; $sql = "select * from emp limit " . ($pageNow - 1) * $pageSize . ",$pageSize"; $res = $mysqli->query($sql); if (! $res) { die("查詢出錯"); } else { echo "<table border='1px' bordercolor='green' cellspacing='0px'>"; echo "<tr><th>id</th><th>name</th><th>grade</th><th>email</th><th>salary</th><th>修改使用者</th><th>刪除使用者</th></tr>"; while ($row = $res->fetch_assoc()) { echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['grade']}</td><td>{$row['email']}</td><td>{$row['salary']}</td> <td><a href='#'>修改使用者</a></td><td><a href='#'>刪除使用者</a></td></tr>"; } echo "</table>"; } echo "<a href='EmpList.php?page=1'>首頁</a>&nbsp;&nbsp"; if ($pageNow > 10) { $moveLeft = $pageNow - 10; echo "<a href='EmpList.php?page=$moveLeft'><<</a>&nbsp;&nbsp"; } if ($pageNow > 1) { $currentTop = $pageNow - 1; echo "<a href='EmpList.php?page=$currentTop'>上一頁</a>" . " "; } if ($pageNow >= 10) { for ($i = $pageNow - 10 + 1; $i <= $pageNow; $i ++) { echo "<a href='EmpList.php?page=$i'>" . $i . "</a>" . " "; } } else { for ($i = 1; $i <= 10; $i ++) { echo "<a href='EmpList.php?page=$i'>" . $i . "</a>" . " "; } } if ($pageNow < $pageCount) { $currentTop = $pageNow + 1; echo "<a href='EmpList.php?page=$currentTop'>下一頁</a>" . " "; } if ($pageNow < $pageCount - 10) { $moveRight = $pageNow + 10; echo "<a href='EmpList.php?page=$moveRight'>>></a>"; } echo "<a href='EmpList.php?page=$pageCount'>末頁</a>&nbsp;&nbsp"; echo "<br/>"; echo "當前頁:" . $pageNow . "/" . $pageCount; ?>
<form action="EmpList.php" method="get"> 跳轉到:<input type="text" name="page" /><input type="submit" value="go" /> </form> </html> </html>
自我複製插入資料測試專用:
INSERT INTO emp (name,grade,email,salary)SELECT name,grade,email,salary from emp;