如何在mysql中正确使用soundex()

时间:2018-07-04 11:51:58

标签: mysql soundex

您好,我正在练习使用Vanilla PHP构建电子商务网站,我希望当我在搜索栏中搜索某个项目时,即使有错字,例如“流量”,仍然可以找到该项目的流量。下面的代码似乎仅适用于正确的拼写和不完整的单词。

 <?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%'"

    ?>

1 个答案:

答案 0 :(得分:0)

以这种方式尝试查询

 $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+")";