由於你們中的一些人的大力幫助,我終於在我的第一個分頁計劃中取得了成功......差不多。如何完成分頁執行
我的劇本奇妙地工作,除了一個小小的順利。有40個「行」頁面,當沒有更多的「行」要顯示時,分頁繼續分頁空白頁面
更具體地說,第13頁是包含行的最後一頁,但您可以仍然打到下一頁並進入空白頁
解決方案很明顯 - 如果沒有剩下行,「下一步」按鈕會消失,但由於某種原因,我所嘗試的所有if語句都無法執行。所以
下面是該查詢:
$rowsperpage = 40; // THERE ARE 40 AIRWAVES PER PAGE
$currentpage = (int)$_GET['currentpage']; // This is getting which "page" the user wants to see, and putting it in $currentpage
if ($currentpage > 0) { // If $currentpage is greater than 0, we'll need to compensate by subtracting 1, so that we pull the correct set of results. Otherwise, we'll just start at 0 (see the else)
$offset = ($currentpage - 1) * $rowsperpage;
}
else {
$offset = 0;
}
$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)) {
,這裏是分頁鏈接:提前
// find out how many rows are in the table
$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;
// 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
$prevpage = $currentpage - 1;
echo "<div id='all_page_turn'>
<ul>
<li class='PreviousPageBlog round_10px'>
<a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$prevpage'>Previous</a>
</li>
<ul>
</div>";
} // end if
// 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 " <div id='all_page_turn'>
<ul>
<li class='PreviousPageBlog round_10px'>
<a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$nextpage'>Next</a>
</li>
</ul>
</div> ";
}
感謝
愛你的意見..尤其是你的第一個 – dynamic
多少F *每個頁面的CKING航空波?!? –
哈哈 - 哎呀忘了那:)我會改變。一個朋友的笑話。 – LightningWrist