直接上马:$page = isset($_GET['p'])? $_GET['p']:1;
$page = ($page ==0)? 1 : $page;
$y = 5;
$x = ($page-1)*$y;
$dsn = "mysql:host=localhost;dbname=demo;charset=utf8";
$pdo = new PDO($dsn,'root','root');
$sql = "SELECT * FROM `user1` LIMIT :x,:y ";
$pdoStmt = $pdo->prepare($sql);
$pdoStmt->bindParam('x',$x,PDO::PARAM_INT);
$pdoStmt->bindParam('y',$y,PDO::PARAM_INT);
$pdoStmt->execute();
echo '
用户信息表
';echo '
echo '
';echo '
IDnameemail';echo '
';foreach($pdoStmt as $row){
echo '
';echo '
'.$row['id'].''.$row['name'].''.$row['email'].'';echo '
';}
echo '
';$sql = "SELECT * FROM `user1`";
$pdoStmt1 = $pdo->prepare($sql);
$pdoStmt1->execute();
//echo $pdoStmt1->rowCount();
$pageC = ceil($pdoStmt1->rowCount()/$y);
$page = ($pageC == $page)? ($page-1):$page;
echo '
';
echo '首页';
echo '上一页';
for($i=1;$i<=$pageC;$i++){
echo ''.$i.'';
}
echo '下一页';
echo '尾页';
echo '';