Php 对这种特殊情况执行sql操作

Php 对这种特殊情况执行sql操作,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,先生 我面临一个问题,如下所示: 我想对$this->db->select('*')->from('table')的输出执行where操作;只有当cond1满足时 $result = $this->db->select('*')->from('table'); if(cond1) { I want to perform $result->where(); operation } 有可能吗?我想知道具体的语法是什么 $this->db->selec

先生

我面临一个问题,如下所示: 我想对$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();

$con1
is应该是一个变量,并且应该有一个值或Null
$con1
类似于布尔值.1或0。如果发生1(true),它将执行if块,如果不发生,它将执行else块。

看起来您想要运行两个不同的查询。假设
$cond1
不依赖于
$result
(在这种情况下,所有下注都已取消),您可以执行以下操作

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

我没有收到你的问题好像我只想在某个条件满足时执行where操作你不能这样做:$result[]=$this->db->where(…)->get()->result();在foreach中,通常,当一个活动记录调用完成时,所有存储的信息都会为下一次调用重置。通过缓存,您可以防止这种重置,并轻松地重用信息。这个真的帮了我很大的忙,先生