當用戶搜索書名時,應使用什麼搜索算法來給出結果?將最近的字符串與特定的字符串匹配
如果存在應該返回標題的書,否則必須顯示與其接近的書名。
第一種情況更容易搜索字符串。我需要如何解決大多數網站使用的第二種情況。
books表包含字段類別,類別和標題。我已經嘗試了下面的代碼,當我給出確切的標題時,我會得到結果,我希望系統給予密切相關的標題。
$title=isset($_GET['title'])?$_GET['title']:NULL;
//$code=isset($_GET['code'])?$_GET['code']:NULL;
$class=isset($_GET['class'])?$_GET['class']:NULL;
$cat=isset($_GET['category'])?$_GET['category']:NULL;
if(isset($title))
$qry="select * from books where quantity>0 and title='$title' ";
else{
$qry="select * from books where quantity>0 ";
if(isset($class)) $qry.=" and class='$class' ";
if(isset($cat)) $qry.=" and category='$cat' ";
}
書名如何存儲?他們在哪裏儲存?你已經嘗試了什麼?我們不在這裏進行舀勺。 – Daniel
@Stah我添加了我曾嘗試過的東西。 – user6181297