下面的HTML表是分页的。在第一页上,$count++
从1开始然后上升,这就是我想要的。
问题在于,当我点击第二页时,$count++
再次从一个开始。
如何从第二页的101开始?
$presult = mysql_query("SELECT COUNT(*) FROM login") or die(mysql_error());
$rr = mysql_fetch_row($presult);
$numrows = $rr[0];
$rowsperpage = 100;
$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;
$tzFrom3 = new DateTimeZone('America/New_York');
$tzTo3 = new DateTimeZone('America/Phoenix');
$sqlStr3 = "SELECT
loginid,
username,
created,
activated
FROM login
WHERE activated = 1
ORDER BY created ASC
LIMIT $offset, $rowsperpage";
$result = mysql_query($sqlStr3);
$arr = array();
echo "<table>";
while ($row = mysql_fetch_array($result)) {
$dt3 = new DateTime($row["created"], $tzFrom3);
$dt3->setTimezone($tzTo3);
echo '<tr class="backgroundnonttsu">';
echo '<td>'.$count++.'</td>';
echo '<td >'.stripslashes($row["username"]).'</a></td>';
echo '<td >'.$dt3->format('F j, Y').'</td>';
echo '</tr>';
}
echo "</table>";
$range = 3;
/****** build the pagination links ******/
// range of num links to show
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=1' class='links'><<</a></div> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$prevpage' class='links'><</a></div> ";
} // 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 " <div class='pages'>[<b>$x</b>] </div>";
// if not current page...
} else {
// make it a link
echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$x' class='links'>$x</a></div> ";
} // 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 " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$nextpage' class='links'>></a></div> ";
// echo forward link for lastpage
//echo " <div class='pages'><a href='http://www.domain.com/directory/file.php?currentpage=$totalpages' class='links'>>></a></div> ";
} // end if
/****** end build pagination links ******/
答案 0 :(得分:1)
if($currentpage==1){
$count=1;
}else{
$count =1+($currentpage*$rowsperpage);
}
答案 1 :(得分:0)
只做
$count = $offset + 1
设置偏移后立即。您只需要一行代码。