doushishi2415 2015-05-15 11:57 采纳率: 0%
浏览 266

在MySql中使用IN Condition进行搜索

I am writing Web services for IOS In cakePhp and stuck in IN condition.

I have a table dog_temperaments and it has values "happy,dependent,shy".

Now if IOS send me array (happy,shy) Then I search Like this

Select dog_temperaments.* where temperaments IN(happy,shy)

Its work fine but if IOS send me array 0 or any(means search by any temperament) Then How I will Search........

Any means Search by all temperaments

  • 写回答

2条回答 默认 最新

  • duanliangman5398 2015-05-15 12:03
    关注

    Either you can check that the array is empty or not like

    if(is_array($array)) {
        Use 
        Select dog_temperaments.* where temperaments IN('happy','shy');
    } else {
        notify Enter proper search key
    }
    

    Else you anyways get the empty results by using the same query if the array is empty like

    Select dog_temperaments.* where temperaments IN(0);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题