Filtering records based on string array PHP and MySQL -


i have string array in php called groups. array looks based on user input: groups[all, sales].

example: (updated table schema)

groups[] = ['sales', 'all']              announcement  |description|masterid|  groupname   | =======================================  | hello     | 1      | all, final,  |  | greetings | 2      | sales, all,  |  | demo      | 3      | final,       | 

so above table should return "hello" , "greetings" output because groups[] has sales , all row 1 has , row 2 has both. please help. amateur in sql , php both.

my current try:

select * announcement groupname regexp '(sales | all)' 

output:

no rows affected 

  1. i guess, groups should in string format: groups[] = ['final', 'all', 'test'].

  2. this $search = implode('|', $groups) produce string final|all|test.

  3. now need put string query search either or words. so, where groupname regexp '({$search})'. don't forget quotes inside query , don't clash quotes put whole query in.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -