doutui7955 2014-10-17 01:37
浏览 7
已采纳

空值MySQL

What is the best way to handle NULL values in a search form. I want to allow the user to search by 8 different criteria however if they leave a box blank I would like it to return all non null values for that column. I am able to assign a default value if the field is left blank but how can I change accountant to "IS NOT NULL"? Thank you for your time.

    if ($specialty_name == null){
        $specialty_name = 'Accountant';
    }

The SQL looks like this... WHERE specialty_name = 'Accountant'

  • 写回答

1条回答 默认 最新

  • douxiong1994 2014-10-17 01:39
    关注

    Something like this:

    if ($specialty_name == null) {
        $where = "WHERE specialty_name IS NOT NULL";
    } else {
        $where = "WHERE specialty_name = '$specialty_name'";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错