http://www.imooc.com/code/591
<?php
// root
// 127.0.0.1
//wlD0fcxMc7vlUFOS
if (function_exists('mysql_connect')) {
echo "Mysql 扩展已经安装<br>";
}
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$dbName = 'sangedaren';
//连接数据库
$link = mysql_connect($host,$user,$pass) or die('数据库连接失败');
mysql_select_db($dbName);
mysql_query("set names 'utf8'");
$page = 4;
$pagesize = 2;
$offset = ($page - 1) * $pagesize;
//分页原理:假如是第三页,每页2个数据,第三页开始的是 (3-1)* 2 = 4,前面有四个数据
//limit m,n 表示从m(这里第4行后)行后取n(这里2行)行数据
$sql = "select * from user limit $offset , $pagesize";
$res = mysql_query($sql);
$data = array();
while ($row = mysql_fetch_array($res,MYSQLI_ASSOC)) {
$data[] = $row;
}
echo '<pre>';
print_r($data);
echo '</pre>';
?>
网友评论