2013-06-12 107 views
0

爵士执行SQL操作,对于这种特殊情况下

我面临的一个问题,它如下所示: 我想执行若对$输出opertion这个 - > DB->选择(“*” ) - >从( '表');只有当COND1满足

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

是否有可能,我还等什么是确切的语法做

+1

像我希望执行的操作,只有当其中某一condtion我没有得到你的问题 – underscore

+0

其满足 –

回答

2

尝试这样的事:

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

$query = $this->db->get(); 
+0

我试了一下它不工作 –

+0

后,如果可能的 – copper

+0

的实际代码http://pastebin.com/MsRZz5Yc她的代码 –

0

$con1是应该是一个变量,它应该有一个值或Null。 $con1就像一个布尔值1或0。如果1(真)发生,它将执行if块,否则它将执行else块。

0

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

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