This.width=700;if (this.offsetheight>700) this.height=700; "border=" 0 "alt=" 鷌 N-Buckle m po m 譵? ' Island po m bencha confused Zhe 譣 v gamma-傔 楗? 栚 aズj 隺 ⒔ 湺? Controller KY "http://bbs.2cto.com" target= "_blank" class= "keylink" > Forum Nicholas_ng
*/
Function page ($page, $total, $phpfile, $pagesize =3, $pagelen =3) {
$pagecode =;//define variables to store page-generated HTML
$page = Intval ($page);//Avoid non-numeric page numbers
$total = Intval ($total);//Guaranteed Total record value type is correct
if (! $total) return array ();//The total number of records is zero returns an empty array
$pages = Ceil ($total/$pagesize);//Calculation of total pages
Handling page numbering legality
if ($page <1) $page = 1;
if ($page > $pages) $page = $pages;
Calculate Query Offset
$offset = $pagesize * ($page-1);
Page range Calculation
$init = 1;//Start Page number
$max = $pages;//End page number
$pagelen = ($pagelen%2)? $pagelen: $pagelen +1;//page number
$pageoffset = ($pagelen-1)/2;//page number offset
Generate HTML
$pagecode =;
$pagecode. = "$page/$pages";//pages, total pages
If this is the first page, the connection to the first and previous pages is not displayed
if ($page!=1) {
$pagecode. = "<<";//First page
$pagecode. = "<";//prev
}
Can be offset when the number of pages is greater than the number
if ($pages > $pagelen) {
If the current page is less than or equal to the left offset
if ($page <= $pageoffset) {
$init = 1;
$max = $pagelen;
}else{//If the current page is greater than the left offset
If the right offset of the current page number exceeds the Max page count
if ($page + $pageoffset >= $pages + 1) {
$init = $pages-$pagelen +1;
}else{
Calculations when left and right offsets are present
$init = $page-$pageoffset;
$max = $page + $pageoffset;
}
}
}
Generate HTML
for ($i = $init; $i <= $max; $i + +) {
if ($i = = $page) {
$pagecode. =. $i.;
} else {
$pagecode. = "$i";
}
}
if ($page! = $pages) {
$pagecode. = ">";//Next page
$pagecode. = ">>";//Last Page
}
$pagecode. =;
Return Array (pagecode=> $pagecode,sqllimit=> limit. $offset.,. $pagesize);
}
?>
===========bkjia offers ====== demo ================
$phpfile = index.php;//Page file name
$page = Isset ($_get[page])? $_get[page]:1;//default page number
$db = mysql_connect (localhost,test,test);//LINK database
mysql_select_db (test, $db);//Select Database
$counts = mysql_num_rows (mysql_query (select ' id ' from ' test ', $db));//Gets the total number of data required
$sql =select ' id ', ' title ' From ' test ';//define Query statement SQL
$getpageinfo = page ($page, $counts, $phpfile);//Call function, raw page HTML and SQL LIMIT clause
$sql. = $getpageinfo [sqllimit];//combined full SQL statement
$data = $row = Array ();//Initialize array
$result = mysql_query ($sql, $db);//Get result set
Loading data into the $data array
while ($row = Mysql_fetch_array ($result)) {
$data []= $row;
}
?>
echo $getpageinfo [pagecode];//display HTML code for pagination
?>
http://www.bkjia.com/PHPjc/486433.html www.bkjia.com true http://www.bkjia.com/PHPjc/486433.html techarticle Forum Nicholas_ng */function page ($page, $total, $phpfile, $pagesize =3, $pagelen =3) {$pagecode =;//define variables, store page-generated HTML $ page = Intval ($page);//Avoid non-numeric page numbers ...