Forum Moderators: open
example : SELECT * FROM tablename WHERE field = 'explode("-",field')...
I cant use the operator LIKE because the field can have records like
12-10-1
97-100-4
86-896-10-67-4
7-5
If I want to search for records with 10, it should only return the 1st and 3rd record.
$some_var = '10';
select * from tablename where field regexp '.*$some_var.*';
or
select * from tablename where field regexp '.*\-$some_var\-.*';
Might have to do an "or" if it's potentially a leading or trailing:
select * from tablename where field regexp '.*\-$some_var\-.*' or field regexp '$some_var\-.*' or field regexp '.*\-$some_var';
you can also try instr() [dev.mysql.com]:
select * from tablename where instr(field,'$some_var');
Though that will match on 100 . . .