我遇到的問題是當搜索詞「反」時它會顯示產品,但是當基於搜索的單詞「反皺紋」沒有提到搜索結果時。請參閱下面的代碼和建議,我錯過了什麼。搜索功能對某些單詞不起作用
$search_output = '';
if(isset($_POST['search'])) {
$searchsql = $_POST['search'];
$searchsql = preg_replace('#[^a-z [email protected]]#i', '', $searchsql);
$query = mysql_query("SELECT tb_spa_prd.*, tb_spa_prd_cat.spa_prd_cat FROM tb_spa_prd AS tb_spa_prd INNER JOIN tb_spa_prd_cat ON tb_spa_prd.spa_prd_cat_id = tb_spa_prd_cat.spa_prd_cat_id WHERE spa_prd_cat LIKE '%$searchsql%' or spa_prd_code LIKE '%$searchsql%' or spa_prd_name LIKE '%$searchsql%'") or die ("Could no search!");
$count = mysql_num_rows($query);
if($count == 0) {
$search_output .= '<tr>
<td colspan="9" style="text-align: center">There was no search results!</td>
</tr>';
} else {
$row_no = 1;
while($row = mysql_fetch_array($query,MYSQL_ASSOC)) {
$spa_prd_id = $row["spa_prd_id"];
$spa_prd_cat = $row["spa_prd_cat"];
$spa_prd_code = $row["spa_prd_code"];
$spa_prd_name = $row["spa_prd_name"];
$spa_prd_vlm = $row["spa_prd_vlm"];
$spa_prd_qty = $row["spa_prd_qty"];
$spa_prd_crt_date = $row["spa_prd_crt_date"];
$spa_prd_crt_usr = $row["spa_prd_crt_usr"];
$search_output .= '<tr>
<td>'.$row_no++.'</td>
<td>'.$spa_prd_cat.'</td>
<td>'.$spa_prd_code.'</td>
<td>'.$spa_prd_name.'</td>
<td>'.$spa_prd_vlm.'</td>
<td>'.$spa_prd_qty.'</td>
<td>'.$spa_prd_crt_date.'</td>
<td>'.$spa_prd_crt_usr.'</td>
<td><a href=\'edit_spa_prd.php?spa_prd_id='.$spa_prd_id.'\'>Edit</a> | <a href=\'delete_spa_prd.php?spa_prd_id='.$spa_prd_id.'\'>Delete</a></td>
</tr>';
} // close while loop
}
}
發佈所有的代碼代替,最好是隻包括所需要的部分。您應打印查詢並將其運行到您的phpmyadmin中以查看結果或調試您自己 –
我建議您將全文索引用於搜索中使用的列。 – Allkin
@Quinn如果你想''反皺紋「'觸發你將需要包括一個單獨的'LIKE'謂詞爲_each_ term,q.v.我的迴應如下。 –