Home  >  Article  >  Backend Development  >  Popular PHP paging effects on the Internet_PHP tutorial

Popular PHP paging effects on the Internet_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:39:00917browse


Popular PHP paging effects on the Internet_PHP tutorialForum 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=

;
return array(pagecode=>$pagecode,sqllimit=> limit .$offset.,.$pagesize);
}
?>


===========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
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486433.htmlTechArticleForum 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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn