I am trying to select a record using the LIKE function. However, it does not show results if there are characters in between. I want it to select data that contains those strings. 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' must be before 'Anthony'
I think Full TEXT works
But Full-text searches are supported for MyISAM
tables only
SELECT * FROM students
WHERE MATCH (name)
AGAINST ('Mark Anthony' IN BOOLEAN MODE)
UPDATE:- As per question update OP need to search Marko
as well, then you can get like this:-
SELECT * FROM students
WHERE
(
name LIKE '%Mark%'
OR name LIKE '%Anthony%'
)
You could split the value string into two parts. Like so:
WHERE name LIKE '%Mark%' AND name LIKE '%Anthony%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With