【发布时间】:2016-08-06 11:30:48
【问题描述】:
当用户搜索书名时,我应该使用什么搜索算法来给出结果?
如果存在应该返回书名的书,否则必须显示靠近它的书名。
第一种情况更容易搜索一个字符串。我需要如何解决大多数网站使用的第二种情况。
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' ";
}
【问题讨论】:
-
书名是如何存储的?它们存储在哪里?你已经尝试过什么?我们不是来喂的。
-
@Stah 我已经添加了我尝试过的内容。
标签: php string-matching