1.先把用户选的区域,价格,类别,品牌提交到服务器端。 2.根据区域,价格,类别,品牌创建条件语句。 如果是全部的不用。 例如用户提交过来 area 区域:朝阳 price 价格:6000元以下 type 类别:社区公寓 brand 品牌:万科地产sql写成 select * from table where area='朝阳' and price<=6000 and type='社区公寓' and brand='万科地产';
这个你可以参考一下php一些开源程序的做法 比如ecshop 的 选择属性 品牌
$sqltext="select &t from newslist where n_pid='".$pid."' "; if($ppid!=""){ $sqltext=$sqltext."and n_ppid= '".$ppid."' ";//价钱不为空连接价钱 } if($pppid!=""){ $sqltext=$sqltext."and n_pppid= '".$pppid."' ";//品牌不为空连接品牌 } if($ortime!=""){ $sqltext=$sqltext."and year(n_time)= '".$ortime."' ";//连接时间 } if($city!=""){ $sqltext=$sqltext."and n_add2= '".$city."' ";;//连接地区 } if($tj!=""){ $sqltext=$sqltext."and n_tjflag= '".$tj."' ";//连接栏目 } if($keytext!=""){ $sqltext = $sqltext." and n_title Like '%".$keytext."%'"; } $sqltext = $sqltext."order by num desc "; 主要是连接sql语句而已
我们接收到这些数据后进行sql拼接select * from table where price < 6000 and location = '平谷' 这里就提取到了数据,然后通过json格式发给前台,前台显示出来。这个过程主要就是ajax异步请求和sql拼接
2.根据区域,价格,类别,品牌创建条件语句。
如果是全部的不用。
例如用户提交过来
area 区域:朝阳
price 价格:6000元以下
type 类别:社区公寓
brand 品牌:万科地产sql写成 select * from table where area='朝阳' and price<=6000 and type='社区公寓' and brand='万科地产';
$sqltext="select &t from newslist where n_pid='".$pid."' ";
if($ppid!=""){
$sqltext=$sqltext."and n_ppid= '".$ppid."' ";//价钱不为空连接价钱
}
if($pppid!=""){
$sqltext=$sqltext."and n_pppid= '".$pppid."' ";//品牌不为空连接品牌
}
if($ortime!=""){
$sqltext=$sqltext."and year(n_time)= '".$ortime."' ";//连接时间
}
if($city!=""){
$sqltext=$sqltext."and n_add2= '".$city."' ";;//连接地区
}
if($tj!=""){
$sqltext=$sqltext."and n_tjflag= '".$tj."' ";//连接栏目
} if($keytext!=""){
$sqltext = $sqltext." and n_title Like '%".$keytext."%'";
}
$sqltext = $sqltext."order by num desc ";
主要是连接sql语句而已