X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..HEAD:/examples/grid-filtering/grid-filter.php diff --git a/examples/grid-filtering/grid-filter.php b/examples/grid-filtering/grid-filter.php index aa8331f2..ec7fea6b 100644 --- a/examples/grid-filtering/grid-filter.php +++ b/examples/grid-filtering/grid-filter.php @@ -1,18 +1,27 @@ query(readCreateSql()); + } + return $db; +} + +function readCreateSql() { + $filename = "grid-demo.sql"; + $file = fopen($filename, 'r'); + $data = fread($file, filesize($filename)); + fclose($file); + return $data; +} // collect request parameters $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0; -$count = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 20; +$count = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 50; $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ''; $dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'ASC'; $filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null; @@ -25,7 +34,6 @@ if (is_array($filters)) { $filters = json_decode($filters); } -// initialize variables $where = ' 0 = 0 '; $qs = ''; @@ -81,21 +89,22 @@ if (is_array($filters)) { $where .= $qs; } -// query the database $query = "SELECT * FROM demo WHERE ".$where; if ($sort != "") { $query .= " ORDER BY ".$sort." ".$dir; } $query .= " LIMIT ".$start.",".$count; -$rs = mysql_query($query); -$total = mysql_query("SELECT COUNT(id) FROM demo WHERE ".$where); -$total = mysql_result($total, 0, 0); - -$arr = array(); -while($obj = mysql_fetch_object($rs)) { - $arr[] = $obj; +$db = getDB(); +$count = $db->singleQuery("SELECT COUNT(id) FROM demo WHERE ".$where); +$result = $db->query($query); +$rows = Array(); +while($row = $result->fetch(SQLITE_ASSOC)) { + array_push($rows, $row); } +echo json_encode(Array( + "total"=>$count, + "data"=>$rows +)); -// return response to client -echo '{"total":"'.$total.'","data":'.json_encode($arr).'}'; \ No newline at end of file +?> \ No newline at end of file