公司要帮一个客户升级他们的网站
其中有个模块是根据勾选的条件来搜索结果
请问大家如何实现这种技术,Query应该怎么写呢
请做过的朋友讲解一下,谢谢下面是这个网站的链接
http://www.highlandhomes.org/search_models.php
其中有个模块是根据勾选的条件来搜索结果
请问大家如何实现这种技术,Query应该怎么写呢
请做过的朋友讲解一下,谢谢下面是这个网站的链接
http://www.highlandhomes.org/search_models.php
分析:首先,每当你勾选一个(或者两个....)复选框,
就是一个类别下的值,这可以理解吧!
相当于你勾选n个类别,n个类别下有值,把每个类别都用数组保存下来,执行sql语句的时候,循环每个类别数组的值,在进行sql操作,这是大概的思路!!!!!数组1
foreach($array_name1 as $array_name){
if($array_name){
执行sql1;
}
数组2
foreach($array_name2 as $array_name){
if($array_name){
执行sql1;
}
以此类推:
在自己组合一个sql语句,相当于
----------------------------
$Dept=null;
$sqlwhere='where';
if(is_numeric($IsDel)&&$IsDel!=2)
$sqlwhere.=($sqlwhere=='where'?'':' and').' IsDel='.$IsDel;
if($DeptID)
$sqlwhere.=($sqlwhere=='where'?'':' and').' DeptID='.$DeptID;
if($DeptName)
$sqlwhere.=($sqlwhere=='where'?'':' and').' DeptName like \'%'.$DeptName.'%\'';
if($DeptNameEn)
$sqlwhere.=($sqlwhere=='where'?'':' and').' DeptNameEn like \'%'.$DeptNameEn.'%\'';
if(is_numeric($IsBiz)&&$IsBiz!=2)
$sqlwhere.=($sqlwhere=='where'?'':' and').' IsBiz='.$IsBiz;
if(is_numeric($IsGZ)&&$IsGZ!=2)
$sqlwhere.=($sqlwhere=='where'?'':' and').' IsGZ='.$IsGZ;
if($FirstChar)
$sqlwhere.=($sqlwhere=='where'?'':' and').' FirstChar=\''.$FirstChar.'\'';
}组合sql执行
query=$sqlwhere=='where'?'':$sqlwhere);