Understanding Partial Matching for Ambiguous Searches

Asked 2 months ago, Updated 2 months ago, 3 views

% value %
This is a conditional expression using LIKE that allows to retrieve partially matched records.

I am currently writing the basic processing of the search function that retrieves data from MySQL using PHP.
It's going well until I get the search results, but the display is strange

For example, if you put t1 in the search form and there is a record called test1, you will get a record called test1

The reason is that somehow I noticed that the front and back matches (%) and the back matches (%), so the letters at the beginning and the end match.
I thought...what do you think?

Here's a part of the code.

$stmt=$pdo->prepare("select*from search where word LIKE:word");
$stmt->execute([(':word'=>"%$word%");

$word contains the values entered in $_POST

What I want to achieve is

Do not retrieve matching records just because you enter the first and last characters.
Match only the characters that follow

Yes, please help me

php mysql

2022-09-30 11:07

1 Answers

% matches an empty string, so %t1% matches test1.


2022-09-30 11:07

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.