In the PHP tutorial +mysql Tutorial Database tutorials in the paging code than the previous ASP tutorials, the ASP.net tutorial is relatively easy, because MySQL support limit,0,n so that you can easily and quickly get the records to read, so let's look at the example
function GetPage ($talbe, $choose, $url) {
Global $page, $db, $sortname;
$query = $db->query ("select * from $talbe $choose");
$total = $db->num_rows ($query);
$totalpage =ceil ($total/25);
$nextpage = $page +1;
$uppage = $page-1;
if ($nextpage > $totalpage) $nextpage = $totalpage;
if ($uppage <1) $uppage = 1;
$showpage = "Total <b><font color= ' #FF0000 ' > $total </font></b> record, total <b><font color= ' #FF0000 ' > $totalpage </font></b> page, currently <b><font color= ' #FF0000 ' > $page </font>< /b> Page
<b><font color= ' #FF0000 ' >◇</font></b><a href= '? $url &page= $uppage &sortname=$ Sortname ' > Prev </a><b><font color= ' #FF0000 ' >◇</font></b><a href= '? $url & page= $nextpage &sortname= $sortname ' > next page </a><font color= ' #FF0000 ' ><b>◇ ';
return $showpage;
}
function Reto ($msg, $url = ') {
Global $comeurl;
if (! $url) $url = $comeurl;
return "<table width= ' 100% ' cellspacing= ' 1 ' cellpadding= ' 3 ' bgcolor= ' #CCCCCC ' >
<tr bgcolor= ' #FFFFFF ' >
<td>
<div align= ' center ' ><font size= ' +6 ' ><b><font size= ' 5 ' ><a href= ' $url ' >& Lt;font color= ' #993300 ' > $msg </font></a></font></b></font></div>
</td>
</tr>
</table> ";
}
through the page of the code we can see the original PHP page is very simple, as long as get[page] page, the current page, and then use the $page* $pagesize to start, after the end of the $pagesize OK. The MySQL statement is $sql = "SELECT * FROM t limit $page * $pagesize, $pagesize";