如何根据 IF 条件执行 Mysql SELECT 语句?
我想将 2 个 mysql 调用合并为一个带有 if 条件的调用。这就是我目前拥有的:
IF
mysql_query("SELECT File FROM DB.ShoePics WHERE Cover='1' AND ShoeID='$ShoeID' LIMIT 1")
Else
mysql_query("SELECT File FROM DB.ShoePics WHERE Cover='0' AND ShoeID='$ShoeID' LIMIT 1")
我想它看起来会与此类似,但我知道它不正确:
mysql_query("SELECT File FROM DB.ShoePics WHERE IF(Cover='1')ELSE(Cover='0') AND ShoeID='$ShoeID' LIMIT 1")
有人可以告诉我怎么做吗?谢谢!
I want to combine 2 mysql calls into one with and if condition. This is what I currently have:
IF
mysql_query("SELECT File FROM DB.ShoePics WHERE Cover='1' AND ShoeID='$ShoeID' LIMIT 1")
Else
mysql_query("SELECT File FROM DB.ShoePics WHERE Cover='0' AND ShoeID='$ShoeID' LIMIT 1")
I guess it would look something similar to this but I know its incorrect:
mysql_query("SELECT File FROM DB.ShoePics WHERE IF(Cover='1')ELSE(Cover='0') AND ShoeID='$ShoeID' LIMIT 1")
Can someone show me how? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让你的查询像
make your query like
mysql_query("从 DB.ShoePics 中选择文件,其中 (Cover='1' AND ShoeID='$ShoeID' LIMIT 1") OR (Cover='0' AND ShoeID='$ShoeID' LIMIT 1")
mysql_query("SELECT File FROM DB.ShoePics WHERE (Cover='1' AND ShoeID='$ShoeID' LIMIT 1") OR (Cover='0' AND ShoeID='$ShoeID' LIMIT 1")