X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/d41dc04ad17d1d9125fb2cf72db2b4782dbe3a8c..c8256059947f3aa8f5b0a9a2acf55e2142bb4742:/examples/grid-filtering/grid-filter.php diff --git a/examples/grid-filtering/grid-filter.php b/examples/grid-filtering/grid-filter.php index 1fc421cb..aa8331f2 100644 --- a/examples/grid-filtering/grid-filter.php +++ b/examples/grid-filtering/grid-filter.php @@ -1,53 +1,90 @@ ".$filter[$i]['data']['value']; Break; - } - Break; - case 'date' : - switch ($filter[$i]['data']['comparison']) { - case 'eq' : $qs .= " AND ".$filter[$i]['field']." = '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break; - case 'lt' : $qs .= " AND ".$filter[$i]['field']." < '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break; - case 'gt' : $qs .= " AND ".$filter[$i]['field']." > '".date('Y-m-d',strtotime($filter[$i]['data']['value']))."'"; Break; - } - Break; - } - } - $where .= $qs; +// connect to database +mysql_pconnect($server, $username, $password) or die("Could not connect"); +mysql_select_db($database) or die("Could not select database"); + +// collect request parameters +$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0; +$count = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 20; +$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ''; +$dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'ASC'; +$filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null; + +// GridFilters sends filters as an Array if not json encoded +if (is_array($filters)) { + $encoded = false; +} else { + $encoded = true; + $filters = json_decode($filters); +} + +// initialize variables +$where = ' 0 = 0 '; +$qs = ''; + +// loop through filters sent by client +if (is_array($filters)) { + for ($i=0;$ifield; + $value = $filter->value; + $compare = isset($filter->comparison) ? $filter->comparison : null; + $filterType = $filter->type; + } else { + $field = $filter['field']; + $value = $filter['data']['value']; + $compare = isset($filter['data']['comparison']) ? $filter['data']['comparison'] : null; + $filterType = $filter['data']['type']; + } + + switch($filterType){ + case 'string' : $qs .= " AND ".$field." LIKE '%".$value."%'"; Break; + case 'list' : + if (strstr($value,',')){ + $fi = explode(',',$value); + for ($q=0;$q ".$value; Break; + } + Break; + case 'date' : + switch ($compare) { + case 'eq' : $qs .= " AND ".$field." = '".date('Y-m-d',strtotime($value))."'"; Break; + case 'lt' : $qs .= " AND ".$field." < '".date('Y-m-d',strtotime($value))."'"; Break; + case 'gt' : $qs .= " AND ".$field." > '".date('Y-m-d',strtotime($value))."'"; Break; + } + Break; + } + } + $where .= $qs; } +// query the database $query = "SELECT * FROM demo WHERE ".$where; if ($sort != "") { - $query .= " ORDER BY ".$sort." ".$dir; + $query .= " ORDER BY ".$sort." ".$dir; } $query .= " LIMIT ".$start.",".$count; @@ -57,8 +94,8 @@ $total = mysql_result($total, 0, 0); $arr = array(); while($obj = mysql_fetch_object($rs)) { - $arr[] = $obj; + $arr[] = $obj; } -echo '{"total":"'.$total.'","data":'.json_encode($arr).'}'; -?> \ No newline at end of file +// return response to client +echo '{"total":"'.$total.'","data":'.json_encode($arr).'}'; \ No newline at end of file