Skip to content
Advertisement

MySQL PHP, SELECT WHERE condition is an array

I am trying to SELECT products from db WHERE condition is an array. My method is working when array is declared but not when elements of array are generate after submitting form.

JavaScript

the problem (i think) is in array, because when I am using one element from the array:

JavaScript

is working correctly it is also working when using:

JavaScript

Advertisement

Answer

WHERE category_name IN ('$selected_categories') is wrong – the parameter will be treated as ONE string literal, not as a list of separate literals.

Use WHERE FIND_IN_SET(category_name, '$selected_categories').

Separate values in $selected_categories must be separated by comma strictly (if some another separator is used then replace it).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement