The mysql table that I’m using looks like:
id | name | other_names
---------------------------------
1 | john | peter johny mike
2 | jane | kevin pite janes john
3 | carl | carlo nick pole
I want to get as a result of the query id# of each user that in the table “other_names” contains the names starting with the word from the query. For example, if the word in query is “joh” a need to get as result ID 1 and 2.
I tried with a query containing LIKE %joh% but as a result I’m getting each user ID# that the column “other names” has a name that contains the word from the query.
SELECT * FROM table WHERE name LIKE '".$word."%' OR other_names LIKE '%".$word."%'
I need that the names from column “other_names” begins with the word from the query, not to contains the word.
You need REGEXP operator and border keyword