I am trying to make a simple program to search for a partial address in PHP. In the table in question there is a column "address". My goal is for the user to enter an incomplete address in the form and get a script of 25 closest matches in this table.
The obvious and, in my opinion, careless way to do this would be to select each address in the table, and then the PHP cycle to go through each of them, calculate the percentage similarity with the search term, arrange them and output them. It seems like a big waste of resources when you consider that the table has tens of thousands of rows, and I'm looking for a maximum of 25.
I would like to do something like this:
SELECT id, firstname, lastname, PERCENTMATCH(address, $searchterm) AS matchpercent
FROM accounts
WHERE matchpercent > 85
ORDER BY matchpercent
LIMIT 25
However, I could not find a way to do this from my request. Is this possible, or do I need to go the casual way?
source
share