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
i guess, groups should in string format:
groups[] = ['final', 'all', 'test']
.this
$search = implode('|', $groups)
produce stringfinal|all|test
.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
Post a Comment