Php 或_where内部where函数活动记录
我想问一下,你们中是否有人知道如何在where-in-codeigniter中放置或_-where 我想创建一个查询,如下所示Php 或_where内部where函数活动记录,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想问一下,你们中是否有人知道如何在where-in-codeigniter中放置或_-where 我想创建一个查询,如下所示 select * from table where ( (in = 0 and call_in = 1) or (out = 0 and call_out = 1) ) and mid = 0 ORDER BY id DESC limit 1 我创造了这样的东西 $result = $mysql_handler->select('*')
select *
from table
where
(
(in = 0 and call_in = 1) or
(out = 0 and call_out = 1)
) and
mid = 0
ORDER BY id DESC
limit 1
我创造了这样的东西
$result = $mysql_handler->select('*')
->from("table")
->where(
array(
"in" => 0,
"call_in" => 1
)
)
->or_where(
array(
"out" => 0,
"call_out" => 1
)
)
->where("mid", 0)
->order_by("id", "DESC")
->limit(1)
->get();
select *
from table
where
(in = 0 and call_in = 1) or
(out = 0 and call_out = 1) and
mid = 0
ORDER BY id DESC
limit 1
但我知道这是不对的,因为这段代码会产生类似的结果
$result = $mysql_handler->select('*')
->from("table")
->where(
array(
"in" => 0,
"call_in" => 1
)
)
->or_where(
array(
"out" => 0,
"call_out" => 1
)
)
->where("mid", 0)
->order_by("id", "DESC")
->limit(1)
->get();
select *
from table
where
(in = 0 and call_in = 1) or
(out = 0 and call_out = 1) and
mid = 0
ORDER BY id DESC
limit 1
我想把or_where放在where子句中,但我不确定这是否正确,也不知道如何做。请告知,谢谢。您不能根据需要将
where
和或
组合在一起或_where
可用于仅需要或
查询的情况。你可以试试这个解决方案
$this->db->from('table');
$this->db->select('*');
$this->db->where('((in = 0 and call_in = 1) OR (out = 0 and call_out = 1))');
$this->db->where("mid", 0);
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result=$this->db->get();
或
有没有一种方法可以让它看起来像一个准备好的陈述?例如,“((in=?和call_in=?)或(out=?和call_out=?)”,数组(0,1,0,1)),我不确定这是否可行