Is the syntax right?
SELECT *
FROM productOp开发者_如何学JAVAtions
WHERE productOptionsID IN ('1,2,3,4')
Have I used IN properly, or should the comma separated values be different?
This is followed by the following code:
$optionsresultsql= mysql_query($optionsquerysql) or die(mysql_error());
while($optionssql = mysql_fetch_array($optionsresultsql)) {
$optionNamesID = $optionssql["optionNamesID"];
echo $optionNamesID;
}
Only one result is shown, even though there are 4 matches in the DB.
remove the single-ticks when dealing with INT lookups..
"SELECT * FROM productOptions WHERE productOptionsID IN (1,2,3,4)"
'1,2,3,4'
is a string, which is being converted to an int. MySQL converts strings to ints by reading up until the 1st non-number character, in your case, the ,
.
So,
IN ('1,2,3,4') = IN (CAST('1,2,3,4' AS INT)) = IN (1)
The query should just be:
productOptionsID IN (1,2,3,4)
精彩评论