I have a node.js application where I want to dynamically implement a mysql query that goes along the lines of:
SELECT * from USERS where col LIKE %value1% or col LIKE %value2% or col LIKE %value3% etc.
The values value1, value2, value3 etc. are values that are sent to the back-end by a user - the user will decide how many values to send, as well as the values themselves. At first I thought I could store these values all in an array, but apparently the LIKE operator will only achieve the desired result of the aforementioned query when the where conditions are chained by multiple ORs (thus a parametrized query like the aforementioned won't work because we don't know how many values there will be). I thought of something like:
SELECT * from USERS where col IN (value1,value2,value3 etc.) but this would only work with the IN operator, and I want the col value to contain the strings rather than be equal to them. Would anyone know how to dynamically achieve this?
Take the user's input in an array and loop through in the input array and create Like query with each item of array push in new array. And join the item pushed in array by OR. And pass newly created and joined array to your query.