duanhuan5409 2011-07-10 07:58
浏览 33

Mysql WHERE子句帮助

How can I use a WHERE MySQL clause in a statement which can fetch me all the records? I am settings the WHERE condition conditionally. Like...

if (this) {
    $mycondition=1;
} elseif (that {
    $mycondition=????
}

'SELECT * FROM table WHERE category='.$mycondition

What should be the value of ???? so that when I pass it to the sql statement it fetches me all the records. I was thinking that WHERE category='*' might work but it does not.

  • 写回答

3条回答 默认 最新

  • douqi2804 2011-07-10 08:01
    关注

    You could just use this

    if(this){
       $mycondition=" category=1";
    }elseif(that{
       $mycondition= " 1"; //1 = 'true'. You could also use "1=1
    }
    
    'SELECT * FROM table WHERE '.$mycondition
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程