开发者

How to do a Mysql SELECT statement based on IF condition?

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') AN开发者_高级运维D ShoeID='$ShoeID' LIMIT 1")

Can someone show me how? thanks!


make your query like

SELECT File FROM DB.ShoePics WHERE (Cover='1' OR Cover='0') AND ShoeID='$ShoeID' LIMIT 1


SELECT File 
FROM DB.ShoePics 
WHERE  
    CASE WHEN CONDITION=1 THEN Cover='1' ELSE Cover='0' END
    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")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜