这是我的代码片段,它返回所有记录,而我希望只返回最接近的匹配
if (isset($_POST['name_query'])){
if(preg_match("/^[ 0-99 a-zA-Z]+/", $_POST['name_query']))
$sql="SELECT client_id, id_num, name, surname FROM clients WHERE name LIKE '%" . $name_query."%' " ;
else if(isset($_POST['surname_query'])){
if(preg_match("/^[ 0-99 a-zA-Z]+/", $_POST['surname_query'])){
$sql="SELECT client_id, id_num, name, surname FROM clients WHERE surname LIKE '%" . $surname_query."%' " ;
elseif (isset($_POST['id_query'])){
if(preg_match("/^[ 0-99 ]+/", $_POST['id_query'])){
$sql="SELECT client_id, id_num, name, surname FROM clients WHERE client_id LIKE '%" . $id_query."%' " ;
答案 0 :(得分:0)
您可以使用之类的这个查询 - 我在Joomla-Page中使用它进行自定义搜索。在此查询中,我使用“searchword”作为我们正在搜索的单词。
CEIL((LENGTH(标题)-length(REPLACE(LOWER(标题),低级( '搜索内容'), '')))/ LENGTH( '搜索内容')* 10 +(LENGTH(introtext)-length( REPLACE(LOWER(introtext),LOWER('searchword'),'')))/ LENGTH('searchword')* 1)AS points