亚洲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ù)研究。

  1.      function _makeCondition($field, $oper, $string){
  2.             $condition="";
  3.               switch ($oper){
  4.                  case "eq":
  5.                     $condition=$field . " " . "=" . " " . "'" . $string . "'";
  6.                  break;
  7.                  case "ne":
  8.                     $condition=$field . " " . "<>" . " " . "'" . $string . "'";
  9.                  break;
  10.                  case "lt":
  11.                     $condition=$field . " " . "<" . " " . "'" . $string . "'";
  12.                  break;
  13.                  case "le":
  14.                     $condition=$field . " " . "<=" . " " . "'" . $string . "'";
  15.                  break;
  16.                  case "gt":
  17.                     $condition=$field . " " . ">" . " " . "'" . $string . "'";
  18.                  break;
  19.                  case "ge":
  20.                     $condition=$field . " " . ">=" . " " . "'" . $string . "'";
  21.                  break;           
  22.                  case "bw":
  23.                   $condition="$field"." ". "like ". "'".$string ."%'";
  24.                   break;
  25.                  case "ew":
  26.                   $condition="$field"." ". "like "."'%". $string . "'";
  27.                   break;
  28.                  case "cn":
  29.                    $condition="$field"." ". "like "."'%". $string ."%'";
  30.                    break;
  31.                   default:
  32.                     $condition=$field . " " . $oper . " " . "'" . $string . "'";
  33.                     break;
  34.               }
  35.         return $condition;      
  36.     }  

  37.            $filters = json_decode($_REQUEST['filters'], true);
  38.            $operation = $filters['groupOp'];      
  39.            $rules = $filters['rules'];
  40.            print_r($rules);
  41.            foreach ($rules as $rule) {
  42.               $field=$rule['field'];
  43.               $op=$rule['op'];
  44.               $data=iconv('utf-8', 'gb2312', $rule['data']);
  45.               $condition=_makeCondition($field,$op,$data);
  46.               if($where){
  47.                 $where=$where.' '.$operation.' '.$condition;
  48.               }else{
  49.                 $where=$condition;
  50.               }//end $rules if        
  51.            }//end $rules foreach
復(fù)制代碼

作者: arserangel    時(shí)間: 2014-05-23 19:38
8錯(cuò)啊,樓主...




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2