this may have been answered before but i have not found something working for me.
i am trying to implement the toolbar search option for jqgrid with php/json data.
so far i have the following
<script src="js/jquery-1.11.0.min.js"></script>
<script type='text/javascript' src='js/jquery-ui-1.8.4.custom.min.js'></script>
<script type='text/javascript' src='js/i18n/grid.locale-es.js'></script>
<script type='text/javascript' src='js/jquery.jqGrid.min.js'></script>
<script>
$(document).ready(function () {
$("#list_records").jqGrid({
url: "grid.php",
datatype: "json",
mtype: "GET",
colNames: ["ID", "Encuesta", "Fecha", "Quien"],
colModel: [
{ name: "id_consulta"},
{ name: "texto"},
{ name: "fecha"},
{ name: "quien"}
],
pager: "#perpage",
rowNum: 10,
rowList: [10,20],
sortname: "id_consulta",
sortorder: "asc",
height: 'auto',
viewrecords: true,
gridview: true,
caption: ""
});
$('#list_records').jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "bw"});
});
</script>
i set the stringresult: true and tried to get the filters.
the correpsonding php file is
$db = mysql_connect($server,$user,$pass);
mysql_select_db($dbname,$db);
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
$filterResultsJSON = json_decode($_REQUEST['filters']);
$filterArray = get_object_vars($filterResultsJSON);
$counter = 0;
$sql='';
while($counter < count($filterArray['rules']))
{
$filterRules = get_object_vars($filterArray['rules'][$counter]);
if($counter == 0){
$sql .= ' WHERE ' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
}
else {
$sql .= ' AND ' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
}
$counter++;
}
$totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
if($totalrows) {$limit = $totalrows;}
$result = mysql_query("SELECT COUNT(*) AS count FROM consulta $sql");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$SQL = "SELECT * FROM consulta $sql ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row['id_consulta'];
$responce->rows[$i]['cell']=array($row['id_consulta'],utf8_encode($row['texto']),$row['fecha'],$row['quien']);
$i++;
}
echo json_encode($responce);
i am getting the following error message upon calling the php directly Warning: get_object_vars() expects parameter 1 to be object, null given in /home/www2w/public_html/tuvoto/grid.php on line 16 Couldn't execute query.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
any help apreciated