2013-05-04 129 views
2

目前我的应用程序有一个高级搜索表单,它使用Ajax/php来查询数据库。我的表单字段如下: 姓名,ID,级别,类别实现高级搜索表单的最佳方式是什么?

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

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

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

什么是最好的方法来实现这一目标?是否有任何技术或类似的Solr和Hibernate搜索?

+1

为什么不只是[编辑您的原始问题](http://stackoverflow.com/posts/16379692/edit)?问题可以重新打开。你不必发表一个新的问题...... – Lix 2013-05-04 23:39:59

回答

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") 
{ 
... 
} 
相关问题