<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>easyui</title> <link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css"> <link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css"> <script type="text/javascript" src="../easyui/jquery.min.js"></script> <script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script> <script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script> <script src="index.js"></script> </head> <body> <table id="box"> </table> </body> </html>
$mysqli=new mysqli("localhost","root","root","test"); $page=$_POST['page']; $rows=$_POST['rows']; $page=($page-1)*$rows; $sql="select * from `test` ORDER BY `mid` ASC limit $page,$rows"; //$sql2="INSERT INTO `test`.`log` (`id`, `log`) VALUES (NULL, '$sql')"; //$mysqli->query($sql2); $result=$mysqli->query($sql); $array=array(); while($rows3=$result->fetch_assoc()){ array_push($array,$rows3); } $sql2="select COUNT(*) as count from `test`"; $result2=$mysqli->query($sql2); $rows2=$result2->fetch_assoc(); $arr['total']=$rows2['count']; $arr['rows']=$array; echo json_encode($arr);
total:表示总数量(没有的话不起分页作用)
rows:表示数据
$(function(){ $("#box").datagrid({ title:'毛客资管理表', width:600, height:300, url:'data.php', autoRowHeight:false, columns:[[ {field:'mid',title:'ID',width:50}, {field:'username',title:'用户名',width:100}, {field:'sex',title:'性别',width:50}, {field:'age',title:'年龄',width:50}, {field:'birthday',title:'出生年月',width:100}, {field:'remarks',title:"备注",width:150}, {field:'createtime',title:'创建时间',width:100}, ]], loadMsg:'加载中....', pagination:true, pageSize:5, pageList:[5,10,15,20], }); })