doule6314 2018-09-23 12:29
浏览 43

JsGrid和laravel

I'm new to JsGrid and i am trying to make some functions like https://www.webslesson.info/2018/08/live-table-add-edit-delete-using-php-with-jsgrid-plugin.html in laravel. But i got an error that says Undefined index: id. I am trying to make call data from database with json and populate it in the jsgrid but unsuccessful. Sorry for being a noob. please correct me if im wrong.

Here is my jsgrid.js

$("#validation").jsGrid({
width: "100%",
filtering: true,
editing: true,
inserting: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 15,
pageButtonCount: 5,
autosearch: true,
deleteConfirm: "Do you really want to delete the client?",
controller: {
  loadData: function(filter){
      return $.ajax({
          type: "GET",
          url: "../../../api/users",
          data: filter,
          dataType: "JSON"
      });
  }  
},
fields: [
    { 
        name: "Id", 
        type: "text", 
        width: 30
    },
    { 
        name: "Name", 
        type: "text", 
        width: 150, 
    },
    { 
        name: "Email", 
        type: "text", 
        width: 150
    },
    { 
        name: "Password", 
        type: "text", 
        width: 150, 
    },
    { 
        name: "Created at", 
        type: "text", 
        width: 150
    },
    { 
        name: "Married", 
        type: "checkbox", 
        title: "", 
        width: 30,
        sorting: false 
    },
    { 
        type: "control" 
    }
]

});

and here is my controller

public function ap_index(User $users)
{
    $connect = mysqli_connect("localhost", "root", "", "DCAPT");
    $method = $_SERVER['REQUEST_METHOD'];
    if($method == 'GET')
    {
        $data = array (
            ':Id'   => "%"  .   $_GET['id'] . "%", <------- //The error is here Undefined Index: id
            ':Name'   => "%"  .   $_GET['name'] . "%",
            ':Email'   => "%"  .   $_GET['email'] . "%",
            ':Password'   => "%"  .   $_GET['password'] . "%",
            ':Created_at'   => "%"  .   $_GET['created_at'] . "%"
        );

        $query = "select * from users where id like :Id or name like :Name or email like :Email
                  or password like :Password or created_at like Created_at";

        $statement = $connect->prepare($query);
        $statement = execute($data);
        $result  = $statement->fetchAll();
        foreach($result as $row){
            $output[] = array(
                'Id'        => $row['id'],
                'Name'      => $row['name'],
                'Email'     => $row['email'],
                'Password'  => $row['password'],
                'Created at'=> $row['created_at']
            );
        }
        echo json_encode($output);
    }
}   
  • 写回答

1条回答 默认 最新

  • dtf76989 2018-09-23 12:54
    关注

    Check you MySQL query:

    "select * from users where id like :Id or name like :Name or email like :Email
                      or password like :Password or created_at like Created_at"
    

    You should add '' in search parameters:

    '...where id like '".$data[':Id']."'...'
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度