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")
精彩评论