php - Search for a string in an array through SQL -


this question has answer here:

i have table named 'offers' has column in_stores. contains ids of stores offer available in. graphically table looks this:

id | title    | in_stores 1  | shoes    | 1002,1003 2  | gloves   | 1020,1011 3  | shades   | 1002,1009 4  | hats     | 1010,1002 5  | shoes    | 1220 6  | shirts   | 1010 7  | hats     | 1002 

each value in in_stores saved implode() function through php.

my question: how select in single mysqli query offers available in store id 1002. in example query should return offers id 1,3,4,7. guess should use explode() first results in array , in_array() search specific id in functions unavailable within sql.

this major issue storing comma separated fields.

mysql have function allow searching these, , lot more reliable trying rely on using like. still cannot use index not fast.

select * offers find_in_set('1002', in_stores) 

far better redesign database use table row each value each id.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -