layui表单加文件 php_php结合layui实现前台加后台操作

一:前台加载出前端页面:

HTML:

lay-data="{width:800,height:400, url:'data.php', page:true, id:'test'}

js:

layui.use("table",function(){

var table=layui.table

})

表头加载下就行了主要讲解下对接数据库和返回对象的操作。

二:先连接数据库

header("Content-type:text/html;charset=utf-8");

$zhuji='localhost';

$user='root';

$port=3306;

$pwd='';

$name="test";

$conn=mysqli_connect($zhuji,$user,$pwd,$name,$port);

if(!$conn){

die("连接失败:".mysqli_connect_error());

}

mysqli_query($conn,'set names utf8');//防止数据库乱码必须要加

分页四要素:

1 当前页

2 每页多少条记录//每页多少条记录要和前台对接好,取名最好为limit

3从数据库读取出多少条记录

4总共多少页

$page=isset($_GET["page"])?$_GET["page"]:1;

$limit=10;

$count=mysqli_num_rows(mysqli_query($conn,"select * from area"));

$perpage=ceil($count/$limit);

$sql="select `id`,`Names`,`parentid`,`shortname` from area limit ".($page-1)*$limit.",".$limit;

$result=mysqli_query($conn,$sql);

if(mysqli_num_rows($result)>0){

echo '{"code":0,"msg":"","count":1000,"data":[';

$i=1;

while($row = mysqli_fetch_assoc($result)) {

$i++;

echo json_encode($row);

if($i

echo ",";

}

}

echo "]}";

}

总结:后台返回的json数据必须和前台接口对好,否则会报错,json数据格式为

{"code":0,"msg":"","count":1000,"data":[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57}]}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值