在我的代码点火器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'
基本上,我想做的是,如果我搜索"确实问过问题",我会得到任何不为空的东西,如果我想搜索他们是否问过问题,则向我显示所有不为空。
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);
}
}
if(!empty($var)){
//do stuff
}
在这里,我们检查变量是否不为空,因此!或者你可以使用:
if(isset($var)){
//do stuff
}
这将检查变量是否已设置。或:
if(is_null($var)){
}else{
//do stuff
}
无论你喜欢什么,或者isset和!空通常是我想要的。