寫點最近關於thinkphp中學到的東西

多個條件數組查詢寫法:

$User = new UserModel();

$map['id'] = array('neq',1);

$map['name'] = 'yuanye';

$User->where($map)->select();

查詢“或”條件(_logic)

$where['name'] = array('like', '%yuauye%');

$where['title'] = array('like','%yuauye%');

$where['_logic'] = 'or';

$User->where($where)->select();

結果爲:( name like '%yuauye%') OR ( title like '%yuauye%')

如果需要使用字符串模式查詢使用方法

$User = new UserModel();

$map['_string'] = 'status=1 AND score>10';

$User->where($map)->select();

字符串模式查詢(_string)查詢多個“與”條件中嵌套“與”條件使用,例如:

$User = M("User"); // 實例化User對象

$map['id'] = array('neq',1);

$map['name'] = 'ok';

$map['_string'] = 'status=1 AND score>10';

$User->where($map)->select();

結果爲:( `id` != 1 ) AND ( `name` = 'ok' ) AND ( status=1 AND score>10 )

 


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章