Home >Backend Development >PHP Tutorial >php mysql finds a string in a field
Suppose I want to find a certain string in a field in mysql
Which function should I use? For example,
"owogkwoeag 190 wegaweogkawoeg" "owogkwwegawegoeag 190 wegaweogkawoeg" "owogkwesseseryeag 190 wegaweogkawoeg" I want to find 190
As long as it contains 190 I deleted him
It can only be 190
If 19 or 910 or 91 does not count...
Which function should I use? For example,
"owogkwoeag 190 wegaweogkawoeg" "owogkwwegawegoeag 190 wegaweogkawoeg" "owogkwesseseryeag 190 wegaweogkawoeg" I want to find 190
As long as it contains 190 I deleted him
It can only be 190
If 19 or 910 or 91 does not count...
LIKE
for fuzzy query, you can use the LOCATE()
or POSITION()
function to implement it.
Suppose your table
is:
content | |
---|---|
owogkwoeag 190 wegaweogkawoeg | |
owogkwwegawegoeag 190 wegaweogkawoeg | |
owogkwesseseryeag 190 wegaweogkawoeg | |
qweqweqweqweqwe 901 |
in the content
field in the test
table:
<code class="sql">delete from test where LOCATE('190', content);</code>
or
<code class="sql">delete from test where POSITION('190' IN content);</code>