Home >php教程 >PHP源码 >pdo分页代码

pdo分页代码

WBOY
WBOYOriginal
2016-06-08 17:32:411120browse
<script>ec(2);</script>

pdo分页

$page = $_GET['page'];
$dsn = "mysql:host=localhost;dbname=bbv1";
$db  = new PDO($dsn,'root','');        //pdo链接
$num = 10;                             //每页显示的文章数目
$pagea=($page-1)*$num;
foreach ($db->query("SELECT * from article Limit $pagea,$num") as $row)
  {
        echo "
";
        print_r("删除");
        print_r($row[1]);
        print_r($row[2]);
  print_r($row[3]);
   }
$rs = $db->query("select COUNT(*) from article");    //取得数据总数
$count = $rs->fetchColumn();
$pagenum = ceil($count/$num);
?>


添加文章


文章总数:


文章总页:


For($i=1;$i       
       $show=($i!=$page)?"$i":"$i";
       Echo $show." ";
}
$db=null;
?>
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
Previous article:php字符串处理函数Next article:php读取文件的方法