I am trying to find a word in a string in a mysql database using PHP.
The problem I am facing is that it searches and spits out the result on my PHP page, but any word close to the searched word also gets the result on my page.
to explain this better, let's say I have a line that looks like this:
women clothing
Now, if I search for a word that women, the results are displayed on my page correctly. But if I search for a word men, then the same results are displayed on my page, because the word "women" has the word men in it.
women
men
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 changing '%$sub%'to '$sub', but this does not return any results!
'%$sub%'
'$sub'
can anyone consult on this?
Edit:
category_name , , API.
. , , - , .. ..
, . , .
, "" "", .
MySQL REGEXP, .
REGEXP
SELECT ... WHERE column REGEXP '[[:<:]]$sub[[:>:]]' ...
, , , , , , . , woMEN , MEN .
, , . , : LIKE '% $sub %' , MEN, MEN . .
LIKE '% $sub %'
, , : LIKE $sub% ( ), , MEN . , , MENACE. , @mrun, - $sub %. , .
LIKE $sub%
$sub
%
EDIT:
, , , , , MENS , , , MYSQL , ..
. :
SELECT id, category_name, image_url FROM data WHERE `category_name` LIKE '% $sub %' OR `category_name` LIKE '% $sub' OR `category_name` LIKE '$sub' OR `category_name` LIKE '$sub %' OR `category_name` LIKE '% $sub\' %' OR `category_name` LIKE '% $sub' OR `category_name` LIKE '$sub\'' OR `category_name` LIKE '$sub\' %' GROUP BY category_name
- MATCH AGAINST, FULLTEXT, :
SELECT id, category_name, image_url FROM data WHERE MATCH (`category_name`) AGAINST ('+$sub' IN BOOLEAN MODE) GROUP BY category_name
, , . :
SELECT id, category_name, aw_image_url FROM data WHERE category_name RLIKE '[[:<:]]".$sub."[[:>:]]' GROUP BY category_name
Source: https://habr.com/ru/post/1615395/More articles:JQuery DataTable passes parameter to ajax call to asp.net - jqueryAndroid Volley: 405 unexpected response code - jsonUse Orientdb chart mode in Spring MVC project - javaJQuery DataTable passes parameter to ajax call to asp.net. Invalid JSON primitive - jsonCSS Infinity Symbol - htmlPython condition-based point syntax functions - pythonUpdate CQ5.6.1 to AEM 6.1, authentication issues - aemEffective pairwise correlation for two feature matrices - pythonAligning messages in a NodeJS chat application - javascriptAndroid set max max limit in bytes - androidAll Articles