Home > Backend Development > PHP Tutorial > PHP paging example code_PHP tutorial

PHP paging example code_PHP tutorial

WBOY
Release: 2016-07-20 11:09:57
Original
766 people have browsed it

PHP分页实例代码





php教程 make page list




 
   
   
 
/*
* Created on 2010-4-17
*
* Order by Kove Wong
*/
$link=MySQL_connect(’localhost’,’root’,’haoxiazai1987’);
mysql教程_select_db(’pagelist’);
mysql_query(’set names gbk’);

$Page_size=10;

$result=mysql_query(’select * from v_char’);
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);

$init=1;
$page_len=7;
$max_p=$page_count;
$pages=$page_count;

//判断当前页码
if(empty($_GET[’page’])||$_GET[’page’]<0){
$page=1;
}else {
$page=$_GET[’page’];
}

$offset=$Page_size*($page-1);
$sql="select * from v_char limit $offset,$Page_size";
$result=mysql_query($sql,$link);
while ($row=mysql_fetch_array($result)) {
?>
 


   
   

}
$page_len = ($page_len%2)?$page_len:$pagelen+1;//Page number Number
$pageoffset = ($page_len-1)/2;//The left and right offset of the page number

$key='

';
$key.="$page/$pages "; //Which page, how many pages in total
if($page!=1){
$key.= "First page "; //First page
$key.="< a href="".$_SERVER['PHP_SELF']."?page=".($page-1)."">Previous page"; //Previous page
} else {
$key.="First page";//First page
$key.="Previous page"; //Previous page
}
if($pages> $page_len){
//If the current page is less than or equal to the left offset
if($page<=$pageoffset){
$init=1;
$max_p = $page_len;
}else{//If the current page is greater than the left offset
//If the right offset of the current page number exceeds the maximum number of pages
if($page+$pageoffset>=$pages+1){
$init = $pages-$page_len+1;
}else{
//Calculation when both left and right offsets exist
$init = $page-$pageoffset;
$max_p = $page+$pageoffset ;
}
}
}
for($i=$init;$i<=$max_p;$i++){
if($i==$page){
$key.=' '.$i.'';
} else {
$key.=" ".$i."";
}
}
if($page!=$pages){
$key.=" Next page " ;//Next page
$key.="Last page" ; //Last page
}else {
$key.="Next page"; //Next page
$key.="Last page"; //Last page
}
$key.='
';
?>



ID 文章标题

     
   

     
   
< ;div align="center">

< /body>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444757.htmlTechArticlePHP paging example code!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:/ /www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml he...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template