2011-08-18 52 views
1

计数++函数下面的HTML表格是分页。在一个页面上,在一个$count++开始,然后上升,这就是我想要的。使用与分页

问题是,当我点击第二页时,$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 ******/ 

回答

1
if($currentpage==1){ 
$count=1; 
}else{ 
$count =1+($currentpage*$rowsperpage); 
} 
+0

谢谢......我用\t'if($ currentpage == 1){ $ count = 1; }否则{ $计数=(1 +($当前页* $ rowsperpage) - $ rowsperpage); }' – John

0

只是做

$count = $offset + 1 

你设定偏移之后。你只需要一行代码。