pdo分页
<?php
$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 "<hr>";
print_r("<a href=delete.php?id=".$row[0].">删除</a>");
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);
?>
<hr>
<a href="insert.php">添加文章</a>
<br>
文章总数:<?php echo"$count" ?>
<br>
文章总页:<?php echo"$pagenum"?>
<hr>
<?php
For($i=1;$i<=$pagenum;$i++){
$show=($i!=$page)?"<a href='index.php?page=".$i."'>$i</a>":"<b>$i</b>";
Echo $show." ";
}
$db=null;
?>