Home > Database > Mysql Tutorial > 一个简单的mysql数据库分页的程序模板_MySQL

一个简单的mysql数据库分页的程序模板_MySQL

WBOY
Release: 2016-06-01 14:12:18
Original
1229 people have browsed it

  下面是一个简单的php连接mysql数据库进行数据分页显示的模版.可以按注释说明信息进行修改,里面的sql语句是可以自己改的.
  
  注意分析和观察里面相关分页部分的代码的书写和实现的方式.
  
    $link = mysql_connect('localhost', 'root', '') or die('mysql database connect error');
  mysql_select_db('your database') or die('the selected database is not exist');
  ?>
  //这里插入你的html代码,
    $sql = 'select count(*) count from your_table';
  $result = mysql_query($sql) or die(mysql_errno().": ".mysql_error()."\n");
  $rs=mysql_fetch_object($result);
  $recountCount = $rs->count;
  $show = 20;
  $totalPage = ceil($recountCount/$show);
  $page = (isset($_GET['page']) && $_GET['page']>=0)? $_GET['page']: 0;
  $isLast = ($page==($totalPage-1))? true: false;
  $hasNoPre = ($page==0)? true: false;
  $hasNoNext = ($page==$totalPage-1)? true: false;
  $isFirst = ($page==0)? true:false;
  $start = $page*$show;
  mysql_free_result($result);
  ?>
  //这里插入你的html代码,
  
  $sql = "select * from your_table limit $start,$show";
  $result = mysql_query($sql) or die(mysql_errno().": ".mysql_error()."\n");
  while($rs=mysql_fetch_object($result)){
  //这个循环里的html代码自己更具实际情况修改
  echo $rs->art_id;
  echo "
";
  }
  mysql_free_result($result);
  ?>
  
  
  $str = "共 $recountCount 条记录,当前第 ".($page+1)."/$totalPage 页 ";
  $str .= $isFirst?  "首页 "  : "首页 ";
  $str .= $hasNoPre? "上一页 " : "上一页 ";
  $str .= $hasNoNext? "下一页 " : "下一页 ";
  $str .= $isLast?  "尾页 "  : "尾页";
  echo $str;
  ?>
  
  
  
  
Related labels:
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