drduh44480 2019-04-16 17:17
浏览 44

数据不会显示在启动网格MySQL中

I have been trying to use bootgrid and put my MySQL database, however, the problem I am having is that I can show the bootgrid table the columns everything is there, however, I can't manage to get the data in, it just says no result found.

This is the script I am using:

  <script>
 var grid = $("#student_grid").bootgrid({
ajax: true,
rowSelect: true,
post: function ()
{

  return {
    id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
  };
},

url: "response.php",
formatters: {
        "commands": function(column, row)
        {
            return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-edit\"></span></button> " + 
                "<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-trash\"></span></button>";
        }
    }
    })

This is my response.php:

<?php 
 include_once("updateStudents.php");
$db = new dbObj();
$connString =  $db->getConnstring();

$params = $_REQUEST;

$action = isset($params['action']) != '' ? $params['action'] : '';
$stdCls = new Student($connString);

switch($action) {
 default:
 $stdCls->getStudent($params);
 return;
}
class Student {
protected $conn;
protected $data = array();
function __construct($connString) {
    $this->conn = $connString;
}

public function getStudent($params) {

$this->data = $this->getRecords($params);

echo json_encode($this->data);
  }

function getRecords($params) {
$rp = isset($params['rowCount']) ? $params['rowCount'] : 10;

if (isset($params['current'])) { $page  = $params['current']; } else { $page=1; };  
    $start_from = ($page-1) * $rp;

$sql = $sqlRec = $sqlTot = $where = '';

if( !empty($params['searchPhrase']) ) {   
  $where .=" WHERE ";
  $where .=" ( StudentID LIKE '".$params['searchPhrase']."%' ";    
  $where .=" OR Name LIKE '".$params['searchPhrase']."%' ";

  $where .=" OR Address LIKE '".$params['searchPhrase']."%' )";
 }

 // getting total number records without any search
$sql = "SELECT * FROM `student` ";
$sqlTot .= $sql;
$sqlRec .= $sql;

//concatenate search sql if value exist
if(isset($where) && $where != '') {

  $sqlTot .= $where;
  $sqlRec .= $where;
}
if ($rp!=-1)
$sqlRec .= " LIMIT ". $start_from .",".$rp;


$qtot = mysqli_query($this->conn, $sqlTot) or die("error to fetch tot student data");
$queryRecords = mysqli_query($this->conn, $sqlRec) or die("error to fetch student data");

while( $row = mysqli_fetch_assoc($queryRecords) ) { 
  $data[] = $row;
}

$json_data = array(
  "current"            => intval($params['current']), 
  "rowCount"            => 10,      
  "total"    => intval($qtot->num_rows),
  "rows"            => $data   // total data array
  );

return $json_data;
 }
  ?>

and this is my connection to the database updateStudents.php:

<?php
 Class dbObj{
/* Database connection start */
var $servername = "localhost";
var $username = "root";
var $password = "";
var $dbname = "admin";
var $conn;
function getConnstring() {
    $con = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname) or die("Connection failed: " . mysqli_connect_error());

    /* check connection */
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
    } else {
    $this->conn = $con;
    echo "asdasdas";
    }
    return $this->conn;
}
 }

 ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM