HTML5技术

easyui框架--基础篇(一)--数据表格datagrid(php与mysql交互) - 渡劫的机器猫(2)

字号+ 作者:H5之家 来源:H5之家 2017-07-02 17:03 我要评论( )

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", "

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"}

 

 

 

学习时候的笔记,可能会有一些错误的地方,欢迎各位的批评指点。

反思,复盘,每天收获一点---------------------期待更好的自己

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 轻量级高性能ORM框架:Dapper高级玩法 - 云中客

    轻量级高性能ORM框架:Dapper高级玩法 - 云中客

    2017-07-02 13:02

  • canvas绘画基础(一):认识canvas画布 - yangtoude

    canvas绘画基础(一):认识canvas画布 - yangtoude

    2017-07-01 15:02

  • 【原】无脑操作:eclipse + maven搭建SSM框架 - {name:代码屠夫}

    【原】无脑操作:eclipse + maven搭建SSM框架 - {name:代码屠夫}

    2017-06-30 17:04

  • C#开发移动应用系列(3.使用照相机扫描二维码+各种基础知识) - GuZhenYin

    C#开发移动应用系列(3.使用照相机扫描二维码+各种基础知识) - GuZhen

    2017-06-24 17:01

网友点评
0