0

先生,

我遇到了一个问题,如下所示:我想对 $this->db->select('*')->from('table'); 的输出执行 where 操作 仅当 cond1 满足

 $result = $this->db->select('*')->from('table');
 if(cond1)
 {
  I want to perform $result->where(); operation
 }

有可能吗,我这样做的确切语法是什么

4

3 回答 3

2

尝试这样的事情:

$this->db->select('*');
$this->db->from('table');
if ($cond1)
    $this->db->where(...)

$query = $this->db->get();
于 2013-06-12T15:40:31.577 回答
0

看起来你想运行两个不同的查询。假设这$cond1不依赖于$result(在这种情况下所有赌注都关闭),你可以做类似的事情

if(cond1)
    $result = $this->db->select('*')->from('table')->where(...);
else
    $result = $this->db->select('*')->from('table');
于 2013-06-12T19:56:14.980 回答
0

$con1is 应该是一个变量,它应该有一个值或 Null。$con1像 Boolean.1 或 0 .if 1(true) 发生它会执行 if 块如果不是它会执行 else 块。

于 2013-06-12T15:40:42.383 回答