MySQL Select data-separated rows

I am trying to select a record using the LIKE function. However, it does not show results if there are symbols between them. I want him to select data containing these rows. For example:

 $value = "Mark Anthony";
 $qry ="SELECT * FROM students WHERE name LIKE '%$value%'";

returns these results:

 John Mark Anthony
 Mark Anthony Philipps

but I also want to have results like these

 Mark James Anthony
 Mark Gabriel Anthony Fernandez
 Marko Julian Anthonyo

Any ideas? UPDATE: Mark should be up to Anthony

+4
source share
5 answers

last try:

$value = "Mark Anthony";
$value = str_replace(" ","%",$value);
$qry ="SELECT * FROM students WHERE name LIKE '%$value%'";

not tested!

+1
source

I think Full TEXT works

But full-text queries are only supported for tables. MyISAM

SELECT * FROM students 
  WHERE MATCH (name)
   AGAINST ('Mark Anthony' IN BOOLEAN MODE)

UPDATE: - . According to the issue of updating the OP, you must also search Marko, then you can do the following: -

SELECT * FROM students 
WHERE
(
    name LIKE '%Mark%'
    OR name LIKE '%Anthony%'
)
+6

. :

WHERE name LIKE '%Mark%' AND name LIKE '%Anthony%'
+2

-

SELECT * FROM table WHERE column REGEXP '(Mark).+(Anthony)';
+1

Suppose you say โ€œbring all the results that Marc Anthony containsโ€, so it is. You must set it as

$value = "Mark%Anthony";
0
source

All Articles