返回table数据......登陆

table数据库取数据的处理

土豆烧牛肉2019-06-18 16:02:47255

PHP

$pdo = new PDO("mysql:host=localhost;dbname=tk181;charset=utf8","root","root");

$page = $_GET['page'];

$limit = $_GET['limit'];

$sql = "select id,title,date,source,ifshow from article";

$count = $pdo->query($sql)->rowCount(2);

$start = ($page-1)*$limit;

$sql.=" limit $start,$limit";

$data = $pdo->query($sql)->fetchAll(2);


$arr = ["code"=>0,"msg"=>'ok','count'=>$count,'data'=>$data];


echo json_encode($arr);

HTML

 <script>

    var table = layui.table;

    table.render({

      elem:"#test",

      width:800,

      height:500,

      url:"table.php",

      page:true,

      limits:[10,20,30,40],

      cols:[[

        // {type:'checkbox',LAY_CHECKED:true},

        {field:'id',title:'ID',width:80,sort:true,fixed:'left'},

        {field:"title",title:'标题',width:300},

        {field:'date',title:'发布日期',width:200},

        {field:'source',title:'来源',width:150},

        {field:'ifshow',title:'是否显示',templet:'#ifshow',width:100},

        {title:'操作',toolbar:"#cz",width:150,align:'center',fixed:'right'}

      ]],

    });





    table.on('tool(article)',function(obj){

      var data = obj.data;

      var event = obj.event;

      var tr  = obj.tr;

      if (evt=="edit") {

        //修改

      }else if(evt=="delete"){

        

        //删除

      }


      //复选框监听

      table.on


      console.log(obj);

      obj.del();

      obj.update({

        id:38,title:'haha',date:123,source:'华强',ifshow:0

      });

    })

  </script>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送
  • php.cn