1 <?php ("Content-Type:text/html;charset=utf-8"); include_once("MySQL/mysql.php"); ("HOST", "1xx.0.0.x"); //ip地址 8 define("USERNAME", "root"); 9 define("PASSWORD", ""); 10 define("DBNAME", "mydb"); 11 define("CHARSET", "utf8"); = @mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME) or die("数据库连接失败<span>".mysqli_connect_error()."</span>"); 15 @mysqli_set_charset($conn, CHARSET) or die("字符集编码设置无效"); ↓ datagrid使用了分页的话,其框架自身会向后台传递page、rows这个两个属性值。 =isset($_POST["page"])?$_POST["page"]:"1"; 20 $rows =isset($_POST["rows"])?$_POST["rows"]:"10"; 21 $start=$rows*($page-1); 22 $end=$rows*$page; 23 //↑inset判断是否传值过来,如果出过来输出传入值,如果没有则为:后面的值 =isset($_POST["sort"])?$_POST["sort"]:"id"; 27 $order=isset($_POST["order"])?$_POST["order"]:"desc"; = <<<sql 30 select * from tb1 order by {$sort} {$order} limit {$start},{$rows} 31 sql; = mysqli_query($conn, $sql); = array(); ($row = mysqli_fetch_assoc($res)) { 39 $arr[] = $row; 40 }; =<<<total 44 45 select count(*) from tb1 46 47 total; =mysqli_query($conn, $getTotal); =mysqli_fetch_row($count)[0]; datagrid接收的完整JSON格式为 54 // 简化版JSON:[{},{},{}] =["rows"=>$arr,"total"=>$total]; = json_encode($jsonArr); ; 具体样式为: 63 {"rows":[{"id":"31","username":"\u8d75\u516d","age":"22","sex":"\u7537"}, 64 {"id":"30","username":"\u8d75\u4e94","age":null,"sex":"\u7537"}, 65 {"id":"29","username":"\u8d75\u4e8c","age":"18","sex":"\u7537"}, 66 {"id":"28","username":"\u8d75\u4e09","age":"19","sex":"\u7537"}, 67 {"id":"27","username":"\u8d75\u4e00","age":"13","sex":"\u7537"}, 68 {"id":"27","username":"\u8d75\u56db","age":"20","sex":"\u7537"}, 69 {"id":"26","username":"\u8d75\u4e91","age":"122","sex":"\u5973"}, 70 {"id":"25","username":"\u53f8\u9a6c\u5149","age":"122","sex":"\u5973"}, 71 {"id":"24","username":"\u5c0f\u6dd8\u6c14","age":"23","sex":"\u5973"}, 72 {"id":"23","username":"\u5f20\u4e00","age":"122","sex":"\u5973"}],"total":"19"}
学习时候的笔记,可能会有一些错误的地方,欢迎各位的批评指点。
反思,复盘,每天收获一点---------------------期待更好的自己