如何在 mysql 中正确使用 soundex()
How to properly use soundex() in mysql
你好,我正在练习使用 vanilla PHP 建立一个电子商务网站,我希望当我在搜索栏中搜索某个项目时,即使有 "trffic" 这样的拼写错误仍然可以找到该项目的流量。下面的代码似乎只适用于正确的拼写和不完整的单词。
<?php session_start();
$searchbar=$_POST['searchbar']
include 'includes/db_config.php';
$query ="SELECT items.id, items.product_name , items.price , categories.id,
items.image , categories.description, items.category_id FROM items INNER JOIN categories ON items.category_id = categories.id WHERE product_name LIKE '%$searchbar%' OR description LIKE '%searchbar%'"
?>
尝试用这种方式查询
$query ="SELECT items.id, items.product_name , items.price , categories.id,
items.image , categories.description, items.category_id FROM items INNER JOIN categories ON items.category_id = categories.id WHERE soundex(product_name)=soundex("+$searchbar+") OR soundex(description) = soundex("+$searchbar+")";
你好,我正在练习使用 vanilla PHP 建立一个电子商务网站,我希望当我在搜索栏中搜索某个项目时,即使有 "trffic" 这样的拼写错误仍然可以找到该项目的流量。下面的代码似乎只适用于正确的拼写和不完整的单词。
<?php session_start();
$searchbar=$_POST['searchbar']
include 'includes/db_config.php';
$query ="SELECT items.id, items.product_name , items.price , categories.id,
items.image , categories.description, items.category_id FROM items INNER JOIN categories ON items.category_id = categories.id WHERE product_name LIKE '%$searchbar%' OR description LIKE '%searchbar%'"
?>
尝试用这种方式查询
$query ="SELECT items.id, items.product_name , items.price , categories.id,
items.image , categories.description, items.category_id FROM items INNER JOIN categories ON items.category_id = categories.id WHERE soundex(product_name)=soundex("+$searchbar+") OR soundex(description) = soundex("+$searchbar+")";