| The code is as follows |
Copy Code |
|
Function page ($sql, $pagesize =10, $class = "") {
if (!is_string ($sql)) {return 0;exit;}
$result =mysql Tutorial _query ($sql);
if (! $result) {return 0;exit;}
if (! $recordnum =mysql_num_rows ($result)) {return 0;exit;}
$totalpage =ceil ($recordnum/$pagesize);
$page = (int) $_get[' page '];
if ($page <=1) $page = 1;
if ($page >= $totalpage) $page = $totalpage;
$recordno = ($page-1) * $pagesize;
$sql. = "Limit $recordno, $pagesize";
$result =mysql_query ($sql);
$url =$_server["Php_self"];
if ($page ==1) $str = "Home page | prev";
else $str. = "<a href=" $url? ". $class. " &page=1 "> Home </a>|<a href=" $url? ". $class. " &page= ". ($page-1). "" > Prev </a> ";
if ($page = = $totalpage) $str. = "| next page | last";
else $str. = "|<a href=" $url? ". $class. " &page= ". ($page + 1). "" > next page </a>|<a href= "$url?". $class. " &page= $totalpage "> Last </a>";
$str. = "$totalpage page of the current $page page";
Return Array ($result, $STR);
}
Call method
$sql = "SELECT * from Images order by IMiD";
$result =page ($sql, 16);
|
/*
The simple original is to read from the database through the tutorial to reading the corresponding more records, so that the implementation of pagination.
*/