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条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c