0

首先,我在我的应用程序中使用 JQGrid。将我的 CSS 更改为 Bootstrap CSS 之后。我必须使用数据表。我想重用我的控制器页面,这些页面进行查询以在 JQGrid 中显示数据。

这是我的控制器页面。

<?php

require_once("JsonHeader.php");
$at = $_SESSION['abc'];
$start_date = $_SESSION['start_date'];
$end_date = $_SESSION['end_date'];
if ($_SESSION['list'] == '-1') {
    $user_query = "";
} else {
    $user_list = $_SESSION['list'];
    $user_query = " AND a.user_id IN ($list)";
}
$start_date = $_SESSION['start_date'];
$end_date = $_SESSION['end_date'];

if ($_SESSION['list'] == '-1') {
    $user_query = "";
} else {
    $user_list = $_SESSION['list'];
    $user_query = " AND a.user_id IN ($list)";
}

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid 
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction 
$qtype = '';  // Search column
$query = '';  // Search string
if (isset($_GET['searchField'])) {
    $qtype = mysql_real_escape_string($_GET['searchField']);
}
if (isset($_GET['searchString'])) {
    $query = mysql_real_escape_string($_GET['searchString']);
}
if (isset($_GET['searchOper'])) {
    switch ($_GET['searchOper']) {
        case 'eq':
            $oper = '=';
            $query = mysql_real_escape_string($_GET['searchString']);
            break;
        case 'ne':
            $oper = '!=';
            $query = mysql_real_escape_string($_GET['searchString']);
            break;
        case 'cn':
            $oper = 'like';
            $query = "%".mysql_real_escape_string($_GET['searchString'])."%";
            break;
    }
}
$searchSql1 = ($qtype != '' && $query != '') ? "and $qtype $oper '$query'" : '';

if (!$sidx)
    $sidx = 1; // connect to the database 
$result = mysql_query(sprintf("SELECT  ae.col1,ae.col2,ae.col3, ae.col4,ae.col5,ae.col6,ae.col7,a.col8,a.col9,r.col10,p.col11
                           FROM $tablename3 ae,$tableName a, $tablename1 p, $tablename2 r
                           WHERE ae.col1=$at  $searchSql1
                           AND a.col1 = $at
                           AND a.col5=r.col5
                           AND a.col6=p.col6
                            $user_query"));
$row = mysql_num_rows($result);
$count = $row;
if ($count > 0) {
    $total_pages = ceil($count / $limit);
} else {
    $total_pages = 0;
}
if ($page > $total_pages)
    $page = $total_pages; $start = $limit * $page - $limit; // do not put 
$limit * ($page - 1);
$SQL = sprintf("SELECT  ae.col1,ae.col2,ae.col3, ae.col4,ae.col5,ae.col6,ae.col7,a.col8,a.col9,r.col10,p.col11
                           FROM $tablename3 ae,$tableName a, $tablename1 p, $tablename2 r
                           WHERE ae.col1=$at  $searchSql1
                           AND a.col1 = $at
                           AND a.col5=r.col5
                           AND a.col6=p.col6
                            $query");

$result = mysql_query($SQL) or die("Couldn t execute query." . mysql_error());
$responce = new stdClass();
$responce->page = new stdClass();
$responce->total = new stdClass();
$responce->records = new stdClass();

$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


    $responce->rows[$i]['id'] = $row['col1'];
    $responce->rows[$i]['cell'] = array($row['col1'], $row['col2'], $row['col3'], $row['col4'], $row['col5'], $row['col6'], $time, $row['col7']);
    $i++;
}
echo json_encode($responce);
?>

我怎样才能改变这个数据表?。请给我最好的方法...

4

1 回答 1

0

最后我找到了如何为 DataTable 恢复我的控制器页面。只需更改控制器页面中的 post 变量。喜欢

$_GET['page']; By $_REQUEST['sEcho']
$_GET['rows']; By $_REQUEST['iDisplayStart'],$_REQUEST['iDisplayLength']
$_GET['sord']; $_REQUEST['sSortDir_0']
$_GET['searchString']: $_GET['sSearch']: 

And some changes the json response like 
$ans['iTotalRecords'] = $count;
$ans['iTotalDisplayRecords'] = $count;
$ans['aaData'] = $aadata;

echo json_encode($ans);
于 2012-10-26T04:28:54.403 回答