亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
PHP如何處理jqGrid發(fā)過(guò)來(lái)的復(fù)合查詢Json條件?
[打印本頁(yè)]
作者:
huowz
時(shí)間:
2014-05-10 22:26
標(biāo)題:
PHP如何處理jqGrid發(fā)過(guò)來(lái)的復(fù)合查詢Json條件?
官方demo里只有一個(gè)$where變量,可怎么組合成這個(gè)串沒(méi)有講,F(xiàn)在需要把傳過(guò)來(lái)的json串
filters:
{"groupOp":"OR","rules":[{"field":"area","op":"eq","data":"石家莊"},{"field":"vlanid","op":"eq","data":"4023"},{"field":"vlanid","op":"eq","data":"4024"}],"groups":[{"groupOp":"AND","rules":[{"field":"area","op":"eq","data":"石家莊"},{"field":"vlanyewu","op":"eq","data":" "}],"groups":[]}]}
轉(zhuǎn)化為:
((area = "石家莊" AND vlanyewu = " ") OR area = "石家莊" OR vlanid = "4023" OR vlanid = "4024")
這樣就可以放到查詢條件里。
作者:
huowz
時(shí)間:
2014-05-11 14:21
本帖最后由 huowz 于 2014-05-11 14:30 編輯
已解決!參考這里:
http://bbs.phpchina.com/forum.ph ... p;page=1#pid1614618
。
美中不足就是還不能處理帶括號(hào)的情況,繼續(xù)研究。
function _makeCondition($field, $oper, $string){
$condition="";
switch ($oper){
case "eq":
$condition=$field . " " . "=" . " " . "'" . $string . "'";
break;
case "ne":
$condition=$field . " " . "<>" . " " . "'" . $string . "'";
break;
case "lt":
$condition=$field . " " . "<" . " " . "'" . $string . "'";
break;
case "le":
$condition=$field . " " . "<=" . " " . "'" . $string . "'";
break;
case "gt":
$condition=$field . " " . ">" . " " . "'" . $string . "'";
break;
case "ge":
$condition=$field . " " . ">=" . " " . "'" . $string . "'";
break;
case "bw":
$condition="$field"." ". "like ". "'".$string ."%'";
break;
case "ew":
$condition="$field"." ". "like "."'%". $string . "'";
break;
case "cn":
$condition="$field"." ". "like "."'%". $string ."%'";
break;
default:
$condition=$field . " " . $oper . " " . "'" . $string . "'";
break;
}
return $condition;
}
$filters = json_decode($_REQUEST['filters'], true);
$operation = $filters['groupOp'];
$rules = $filters['rules'];
print_r($rules);
foreach ($rules as $rule) {
$field=$rule['field'];
$op=$rule['op'];
$data=iconv('utf-8', 'gb2312', $rule['data']);
$condition=_makeCondition($field,$op,$data);
if($where){
$where=$where.' '.$operation.' '.$condition;
}else{
$where=$condition;
}//end $rules if
}//end $rules foreach
復(fù)制代碼
作者:
arserangel
時(shí)間:
2014-05-23 19:38
8錯(cuò)啊,樓主...
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2