【转】在ThinkPHP中实现复杂组合查询

针对如下语句:select * from table where ((is_top<>2 and title like '%Think%') or id=5) and status=1
以数组方式给where条件赋值1[code]
$where['is_top']  = array('neq',2);
$where['title']  = array('like', '%Think%');
$where['_logic'] = 'and';
$map['_complex'] = $where;
$map['id']  = array('eq',5);
$map['_logic']='or';
$checks['status']=array('eq',1);
$checks['_complex']=$map;
$checks['_logic']='and';
[/code]以数组方式给where条件赋值2[code]
$wheres=array(
 '_complex'=>array(  
  '_complex'=>array(
         'is_top'=>array('neq',2),
         'title' =>array('like','%Think%'),
         '_logic'=>'and'
         ),
  'id'=>array('eq',5),
  '_logic'=>'or'
  ),
 'status'=>array('eq',1),
 // '_string'=>'status=1',
 '_logic' =>'and'
 );
[/code]在上边的例子中,其实还可以把如 'id'=>array('eq',5),写成多个条件的组合方式[code]
'id'=>array(array('lt',100),array('gt',2),'or')

你可能感兴趣的:(thinkphp,复杂,组合查询)