* 편집 *** 나는 매김 쿼리에서 일부 변수 방송 전파를 가져옵니다 마지막으로 작동하도록 페이지 매김을 입수했습니다 주요 쿼리를 결합하여 큰 진전했습니다매김 도움말
. 유일한 문제는 이제 첫 번째 페이지가 비어 있다는 것입니다 페이지 두 사람은 한계가 쿼리 결과 다음 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 개 결과를 당길 수 모르지만, 그래서 긴 이야기 후 자사의 미세
무엇이 작동하지 않습니까? –
* 정확한 문제 *는 무엇입니까? "[아직도] (http://stackoverflow.com/questions/6287209/how-to-implement-final-steps-in-pagination-project) 할 수 없습니다"는 당신을 도울 너무 애매합니다. – deceze
당신이 쓰는 또 다른 방법입니다. 이전의 것은 무엇 이었습니까? 그리고 실제로 당신의 문제는 무엇입니까? 당신은 방금 코드를 작성하는 데 문제가 있다고 말했기 때문에 코더를 찾으십니까? – hakre