先生,
我遇到了一个问题,如下所示:我想对 $this->db->select('*')->from('table'); 的输出执行 where 操作 仅当 cond1 满足
$result = $this->db->select('*')->from('table');
if(cond1)
{
I want to perform $result->where(); operation
}
有可能吗,我这样做的确切语法是什么
先生,
我遇到了一个问题,如下所示:我想对 $this->db->select('*')->from('table'); 的输出执行 where 操作 仅当 cond1 满足
$result = $this->db->select('*')->from('table');
if(cond1)
{
I want to perform $result->where(); operation
}
有可能吗,我这样做的确切语法是什么
尝试这样的事情:
$this->db->select('*');
$this->db->from('table');
if ($cond1)
$this->db->where(...)
$query = $this->db->get();
看起来你想运行两个不同的查询。假设这$cond1
不依赖于$result
(在这种情况下所有赌注都关闭),你可以做类似的事情
if(cond1)
$result = $this->db->select('*')->from('table')->where(...);
else
$result = $this->db->select('*')->from('table');
$con1
is 应该是一个变量,它应该有一个值或 Null。$con1
像 Boolean.1 或 0 .if 1(true) 发生它会执行 if 块如果不是它会执行 else 块。