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

时间:2019-04-16 17:17:37

标签: php html mysql ajax bootstrap-4

我一直在尝试使用bootgrid并放置我的MySQL数据库,但是,我遇到的问题是我可以向bootgrid表显示所有存在的列,但是,我无法设法获取数据,它只是说没有找到结果。

这是我正在使用的脚本:

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

这是我的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;
 }
  ?>

这是我与数据库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\n", mysqli_connect_error());
    exit();
    } else {
    $this->conn = $con;
    echo "asdasdas";
    }
    return $this->conn;
}
 }

 ?>

0 个答案:

没有答案