*編輯***分頁幫助
我已經通過組合從分頁查詢一些變量拉電波,並最終得到了分頁工作主要查詢取得了很大進展。現在唯一的問題是,第一頁是空白的,第二頁是正確的使用結果41-80
這裏開始,將查詢範圍和拉電波
$rowsperpage = 40;
$currentpage = (int) $_GET['currentpage'];
$offset = ($currentpage - 1) * $rowsperpage;
$query = "SELECT * FROM `CysticAirwaves` WHERE `FromUserID` = `ToUserID` AND `status` = 'active' ORDER BY `date` DESC, `time` DESC LIMIT $offset, $rowsperpage" ;
$request = mysql_query($query,$connection);
$counter = 0;
while($result = mysql_fetch_array($request)) {
這裏是分頁代碼:
$query = "SELECT COUNT(*) FROM `CysticAirwaves`";
$result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 40;
// find out total pages
$totalpages = ceil($numrows/$rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$query2 = "SELECT `id` FROM `CysticAirwaves` LIMIT $offset, $rowsperpage";
$result = mysql_query($query2, $connection) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
// echo data
echo $list['id'] . " : " . $list['number'] . "<br />";
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
所以長話短說,我只是我不能拉頭40倍的結果,但之後,其精
什麼不工作? – 2011-06-13 23:19:25
你有什麼確切的問題? 「[仍然](http://stackoverflow.com/questions/6287209/how-to-implement-final-steps-in-pagination-project)無法」太模糊,以幫助你。 – deceze 2011-06-13 23:20:25
你寫這是另一種方法。前一個是什麼?實際上你的問題是什麼?你剛剛說過你一般都會寫代碼,所以你在尋找一個編碼器嗎? – hakre 2011-06-13 23:21:14