douxi4114 2013-05-09 10:00 采纳率: 100%
浏览 28
已采纳

如何在视图中记录是否为空?

In my codeigniter PHP model I have

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);
            }

Yet when I run a echo $this->db->last_query(); I get this error

'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'  

Basically what I am trying to do is make it a if I search for "did ask question" I get anything that isnt null and if I want to search for if they did ask a question show me all the ones that are not null.

  • 写回答

2条回答 默认 最新

  • duanqian3953 2013-05-09 10:17
    关注
        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);
            }
          }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改