实施高级搜索表单的最佳方法是什么?

时间:2013-05-04 23:15:49

标签: php sql search

目前我的应用程序有一个高级搜索表单,它使用Ajax / php查询数据库。我的表单字段如下: 姓名,身份证,等级,等级

因此,如果用户输入Level和class,它将显示所有具有相同级别和级别的学生......依此类推。

现在我想改进它以允许用户在AND / OR之间进行选择,例如,他想要搜索具有相同名称但在a级或a级中的学生。

select * from table where name like name AND (level == level OR class == class)

实现这一目标的最佳方法是什么?是否有任何类似于Solr和Hibernate Search的技术或类似内容?

1 个答案:

答案 0 :(得分:0)

//get the choice of the user

$choose = $_GET['choose'];

//Make the querys

$query_or = "select * from table where name like name AND (level == level OR class == class)";

$query_and = "select * from table where name like name AND (level == level AND class == class)"

//if has choosen "or" select with the 1st query
if ($choose == "or")
{
...
}

//if has choosen "and" select with the 2nd query
if ($choose == "and")
{
...
}