//Command the model layer to process data
$link=mysql_connect('localhost','root','') or die("failure");
mysql_select_db('books',$link) or die("Error connecting to the database!");
//Display the number of records per page
$pagesize = 2;
//Find the total number of records
$sql = "select count(*) as total_rows from books";
$result = mysql_query($sql);
$total_rows = mysql_fetch_array($result);
//Find the total Number of pages
$pages = ceil($total_rows[0]/$pagesize);
//The current page
$page = $_POST['page'];
$strtext = " Current page ".$page."."Total".$pages."Page"."Total".$total_rows[0]."Record";
//var_dump($str);
//Next, I need to find the corresponding data based on the currently clicked page number
$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) ;
//The data link will be obtained and then returned to
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$ pages;
//Command the view layer to display data
$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);