以下是小妹做出的一個實例:
以上鍊接數據庫部分省略:
//查詢數據得到總共有多少條數據
$sql = “SELECT count() FROM test”; $result = mysqli_query($con, $sql); $count = mysqli_fetch_assoc($result); $count = intval($count[‘count()’]);
$perPage = 5;
$pages = ceil($count/$perPage);
$curPage = isset($_GET[‘p’]) ? min(max((int)$_GET[‘p’],1),$pages) : 1;
$offset = ($curPage - 1) * $perPage;
//最後通過查詢數據使用LIMIT來顯示每頁顯示多條數據即可。
$sql = “SELECT * FROM test ORDER BY id DESC LIMIT $offset,
$perPage”;
$result = mysqli_query($con, $sql);