日期:2014-05-17  浏览次数:20865 次

thinkphp 我想用or 连接
在不
我想问一下
select * from table where id=2 or pid =2

夏草 15:05:10
我想得到上面的语句

我这样写
$map['id'] = '1';
$map['pid'] = '2';
$modle->where($map)->select();

得么的是 and 连起来的

我怎么写一下这个数组呢


------解决方案--------------------
我想,手册中说的很清楚了:
更改默认的逻辑判断,通过使用 _logic 定义查询逻辑
$condition['name'] = 'thinkphp';
$condition['account'] = 'thinkphp';
$condition['_logic'] = 'OR';
// 把查询条件传入查询方法
$User->where($condition)->select(); 

最后生成的SQL语句是
SELECT * FROM think_user WHERE `name`='thinkphp' OR `account`='thinkphp'