1
嘿傢伙我的英語不是很好'但我試圖解釋我的自我清楚。 我創建分頁,我的所有代碼都在工作完美。分頁顯示問題與編號頁
問題是,我想只顯示五個頁數,並點擊下一個按鈕,我隱藏一個並顯示新的。它看起來像那樣。
next 12345 prev
next 23456 prev
感謝您的建議傢伙。
這裏是我的代碼:
<?php
$dbh = new PDO("mysql:host=localhost;dbname=northwind", "root", "123");
$query = $dbh->prepare("SELECT ContactName FROM Customers");
$query->execute();
$numRows = $query->rowCount();
if (isset($_GET['pn'])) {
$pn = $_GET['pn'];
} else {
$pn = 1;
}
$startPage = 1;
$perPage = 9;
$lastPage = ceil($numRows/$perPage);
if ($pn < 1) {
$pn = 1;
} else if ($pn > $lastPage) {
$pn = $lastPage;
}
$controls = '';
if ($pn != $lastPage) {
$controls .= '<a id="next" href="' . $_SERVER['PHP_SELF'] . '?pn=' . ($pn + 1) . '"> next </a>';
}
for ($i=1; $i <= $lastPage; $i++) {
if ($i == $pn) {
$background = ' red;';
} else {
$background = ' green;';
}
$controls .= '<a id="page_' . $i . '" data-page="' . $i . '" class="num" style="background:' . $background . ' " href="' . $_SERVER['PHP_SELF'] . '?pn=' . $i . '"> ' . $i . '</a>';
}
if ($pn != $startPage) {
$controls .= '<a href="' . $_SERVER['PHP_SELF'] . '?pn=' . ($pn - 1) . '"> prev </a>';
}
$controls .= "PAGE " . $pn . " of " . $lastPage ;
$limit = "LIMIT " . ($pn-1) * $perPage . ', ' . $perPage;
$query2 = $dbh->prepare("SELECT ContactName FROM Customers " . $limit . "");
$query2->execute();
$outputList = '';
while($row = $query2->fetch(PDO::FETCH_OBJ)){
$outputList .= '<h1>' . $row->ContactName . '</h1><hr />';
}
把它你能PLS顯示出一些這方面的例子嗎?我不是很瞭解你。謝謝 – Victorino