Home >Backend Development >PHP Tutorial >Popular PHP paging effects on the Internet_PHP tutorial
Forum nicholas_ng
*/
function page($page,$total,$phpfile,$pagesize=3,$pagelen=3){
$pagecode = ;//Define variables to store the HTML generated by paging
$page = intval($page);//Avoid non-numeric page numbers
$total = intval($total);//Ensure that the total record value type is correct
if(!$total) return array();//The total number of records is zero and returns an empty array
$pages = ceil($total/$pagesize);//Calculate total paging
//Process page number legitimacy
if($page
if($page>$pages) $page = $pages;
//Calculate query offset
$offset = $pagesize*($page-1);
//Page range calculation
$init = 1;//Starting page number
$max = $pages;//End page number
$pagelen = ($pagelen%2)?$pagelen:$pagelen+1;//Number of page numbers
$pageoffset = ($pagelen-1)/2;//The left and right offset of the page number
//Generate html
$pagecode=
===========bkJia provides======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));//Get the total number of required data
$sql=select `id`,`title` from `test`;//Define query statement SQL
$getpageinfo = page($page,$counts,$phpfile);//Call function to generate paging HTML and SQL LIMIT clause
$sql.=$getpageinfo[sqllimit];//Combining complete SQL statements
$data = $row = array();//Initialize array
$result = mysql_query($sql,$db);//Get the result set
//Load data into $data array
while($row = mysql_fetch_array($result)){
$data[]=$row;
}
?>
echo $getpageinfo[pagecode];//Display paging html code
?>