I have created a search function on my site that searches my DB using LIKE
as shown here:
$term = $_GET['search'];
$newterm = '%'.$term.'%';
$params = [$newterm];
$sql = "SELECT * FROM products WHERE product_name LIKE ?";
$stmt = DB::run($sql,$params);
However, this isn't great for misspellings or additional characters.
So for example, if my DB contains: [blue hat, red hat, black hat, white hat]. If I search for hat, all the results come back as expected. If I search for hats, I get no results. If I search for hta, I get no results.
Is there a better way to search the DB for similar results or have a warning like Google that says something like this based on what actually is in the DB:
You searched for hta, did you mean hat?