I'm trying to search for a word in a string in mysql database using PHP.
the issue that I am having is that it searches and spits out the result on my PHP page but any word that is close to the searched word is also gets a result on my page.
to explain this better, lets say I have a string which is like this:
women's clothing
now if i search for a word which is women the results are being displayed on my page correctly But If i search for the word men the same results are being displayed on my page because the word women has the word men in it.
this is my current sql query:
SELECT id, category_name, image_url FROM data WHERE `category_name` LIKE '%$sub%' GROUP BY category_name
I tried to change '%$sub%' to '$sub' but that doesn't return any results at all!
could someone please advise on this?
Edit:
the strings in the category_name column vary and they cannot be changed since they are coming from an external API.
these strings could vary. so one might look like Women's Dresses & Skirts and another one might look like Women's shoes and another one might look Women's bags and another one might look like men's shoes etc etc....
so what i need to do is to display all the results for the keyword women and display the results for all the men. I hope that makes sense.
but at the moment, the results of men and women being displayed at the same time because the word Women has the word Men in it as I explained above.
LIKE '% $sub %'? This won't matchmen'sbut I hope you get the ideamenfollowed by!,., etc.