1

在我的 codeigniter PHP 模型中,我有

if  ($this->input->post('questions') != "")
        {
            if($this->input->post('questions') == "Yes")
            {
                $this->db->where('webinar_event.questions !=',"");
                $this->db->where('webinar_event.questions IS NOT ', null, false);
            }
            else
            {
                $this->db->where('webinar_event.questions',"");
                $this->db->where('webinar_event.questions IS', null, true);
            }

然而,当我运行时, echo $this->db->last_query();我得到了这个错误

'Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5

SELECT * FROM (`health_professional`) JOIN `webinar_event` ON `webinar_event`.`hpid` = `health_professional`.`hpid` WHERE `webinar_event`.`questions` = '' AND `webinar_event`.`questions` IS

Filename: D:\Development\PfizerWebinar\web\system\database\DB_driver.php

Line Number: 330'  

基本上我想要做的是,如果我搜索“确实问过问题”,我会得到任何不为空的内容,如果我想搜索他们是否确实问过问题,请向我展示所有不为空的问题。

4

2 回答 2

1
    Try this 


      if  ($this->input->post('questions') != "")
      {
        if($this->input->post('questions') == "Yes")
        {
            $this->db->where('webinar_event.questions !=',"");
            $this->db->where('webinar_event.questions IS NOT NULL', null, false);
        }
        else
        {
            $this->db->where('webinar_event.questions',"");
            $this->db->where('webinar_event.questions IS NULL', null, true);
        }
      }
于 2013-05-09T10:17:12.627 回答
0
if(!empty($var)){
  //do stuff
}

在这里,我们检查变量是否不为空,因此!或者您可以使用:

if(isset($var)){
 //do stuff
}

这将检查变量是否已设置。或者:

if(is_null($var)){

}else{
  //do stuff
}

无论您喜欢哪个,或者 isset 和 !empty 的组合,通常都是我想要的。

于 2013-05-09T10:20:39.517 回答