代码如下:
代码如下:
PHP
//命令模型层处理数据
$link=MysqL_connect('localhost','root','') or die("失败");
MysqL_select_db('books',$link) or die("连接数据库出错了!");
//每页显示记录数
$pagesize = 2;
//求出总的记录数
$sql = "select count(*) as total_rows from books";
$result = MysqL_query($sql);
$total_rows = MysqL_fetch_array($result);
//求总共的页码数
$pages = ceil($total_rows[0]/$pagesize);
//当前第几页
$page = $_POST['page'];
$strtext = "当前第".$page."页"."总共".$pages."页"."共".$total_rows[0]."记录";
//var_dump($str);
//接下来,我要根据当前点击的页码求出对应的数据
$offset = $pagesize*($page-1);
$sql = "select * from books limit $offset,$pagesize";
MysqL_query("set names utf8");
$res=MysqL_query($sql); $rows=array();
while($row=MysqL_fetch_assoc($res)){
$rows[]=$row;
}
$pageInfo = $rows;
//echo json_encode($pageInfo);
//var_dump($pageInfo);
//将获得数据链接,后返回
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages; //命令视图层显示数据
$first_a = "";
if($page>1){
$prev_a = "";
}
if($page<$pages){
$next_a = "";
}
$last_a = "";
@$str = $strtext.$first_a.$prev_a.$next_a.$last_a;
//var_dump($str);
$info = array('str'=>$str,'info'=>$pageInfo);
echo json_encode($info);
//命令模型层处理数据
$link=MysqL_connect('localhost','root','') or die("失败");
MysqL_select_db('books',$link) or die("连接数据库出错了!");
//每页显示记录数
$pagesize = 2;
//求出总的记录数
$sql = "select count(*) as total_rows from books";
$result = MysqL_query($sql);
$total_rows = MysqL_fetch_array($result);
//求总共的页码数
$pages = ceil($total_rows[0]/$pagesize);
//当前第几页
$page = $_POST['page'];
$strtext = "当前第".$page."页"."总共".$pages."页"."共".$total_rows[0]."记录";
//var_dump($str);
//接下来,我要根据当前点击的页码求出对应的数据
$offset = $pagesize*($page-1);
$sql = "select * from books limit $offset,$pagesize";
MysqL_query("set names utf8");
$res=MysqL_query($sql); $rows=array();
while($row=MysqL_fetch_assoc($res)){
$rows[]=$row;
}
$pageInfo = $rows;
//echo json_encode($pageInfo);
//var_dump($pageInfo);
//将获得数据链接,后返回
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages; //命令视图层显示数据
$first_a = "";
if($page>1){
$prev_a = "";
}
if($page<$pages){
$next_a = "";
}
$last_a = "";
@$str = $strtext.$first_a.$prev_a.$next_a.$last_a;
//var_dump($str);
$info = array('str'=>$str,'info'=>$pageInfo);
echo json_encode($info);