开发简述:使用phpcms v9系统,修改源文件5个,创建模型:楼盘、出售、出租、中介、小区,增加联动菜单:楼盘,增加用户组:房产中介。
实现功能:
游客发布信息、会员申请中介、楼盘全方位展示、报名团购、看房功能,发布信息时可根据登陆后的会员资料自动填好联系信息,中介有自己的店铺,可给中介留言,联动筛选搜索、排序,房源对比功能。
联动筛选搜索功能的实现方法及代码:
要修改的文件就是list.html模板
核心代码:
<?php
$theurl = app_path.index.php?m=content&c=index&a=lists&catid=$catid;
$where = status=99;
$orderby = ;
foreach ($_get as $field => $r) {
if($r) {
if(!in_array($field,array('m','c','a','page'))){
if(strrpos($field,'_')){
$arr=explode(-,$r);
$field = str_replace('_','',$field);
$where .= and $field >= '$arr[0]' and $field <= '$arr[1]';
}else if($field == 'title'){
$where .= and $field like .'%.$r.%';
}else if($field == 'orderby'){
$orderby = str_replace('_',' ',$r);
}else{
$where .= and $field='$r';
}
}
}
}
//if($where)$where = substr($where,5);
if(!$orderby)$orderby = id desc;
?>
用这段代码来构造查询条件和排序方式,有了这段代码之后,要把list.htm获得列表的pc语句改造成这样
原来的
{pc:content action=lists catid=$catid num=25 order=id desc page=$page}
改造后的
{pc:content action=lists where=$where catid=$catid num=25 order=$orderby page=$page}
使用的时候就比较麻烦了
<p><span>状态:</span><span><a href='{url_par(price_=$_get[price_]&hstatus=& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>全部</a& amp; gt;</span>
<span {if $_get[hstatus] == 1}class='shaixuan'{/if}><a href='{url_par(price_=$_get[price_]&hstatus=1& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>新盘</a& amp; gt;</span>
<span {if $_get[hstatus] == 2}class='shaixuan'{/if}><a href='{url_par(price_=$_get[price_]&hstatus=2& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>在售</a& amp; gt;</span>
<span {if $_get[hstatus] == 3}class='shaixuan'{/if}><a href='{url_par(price_=$_get[price_]&hstatus=3& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>尾盘</a& amp; gt;</span>
<span {if $_get[hstatus] == 4}class='shaixuan'{/if}><a href='{url_par(price_=$_get[price_]&hstatus=4& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>售完</a& amp; gt;</span></p>
<p><span>均价:</span><span><a href='{url_par(price_=&hstatus=$_get[hstatus]& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>全部</a& amp; gt;</span>
<span {if $_get[price_] == '0-4000'}class='shaixuan'{/if}><a href='{url_par(price_=0-4000&hstatus=$_get[hstatus]& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>4000以下& amp; lt;/a></span>
<span {if $_get[price_] == '4000-5000'}class='shaixuan'{/if}><a href='{url_par(price_=4000-5000&typeid=$_get[typeid]&hstatus=$_get[hstatus]&address=$_get[address],$theurl)}'>4000-5000</a></span>
<span {if $_get[price_] == '5000-6000'}class='shaixuan'{/if}><a href='{url_par(price_=5000-6000&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$_get[address],$theurl)}'>5000-6000</a></span>
<span {if $_get[price_] == '6000-7000'}class='shaixuan'{/if}><a href='{url_par(price_=6000-7000&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$_get[address],$theurl)}'>6000-7000</a></span>
<span {if $_get[price_] == '7000-8000'}class='shaixuan'{/if}><a href='{url_par(price_=7000-8000&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$_get[address],$theurl)}'>7000-8000</a></span>
<span {if $_get[price_] == '8000-9000'}class='shaixuan'{/if}><a href='{url_par(price_=8000-9000&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$_get[address],$theurl)}'>8000-9000</a></span>
<span {if $_get[price_] == '9000-10000'}class='shaixuan'{/if}><a href='{url_par(price_=9000-10000&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$_get[address],$theurl)}'>9000-10000</a></span>
<span {if $_get[price_] == '10000-100000'}class='shaixuan'{/if}><a href='{url_par(price_=10000-100000&hstatus=$_get[hstatus]& typeid=$_get[typeid]&address=$_get[address],$theurl)}'>10000以上& amp; lt;/a></span>
</p>
<p><span>类型:</span><span><a href={url_par(price_=$_get[price_]&hstatus=$_get[hstatus]& typeid=&address=$_get[address],$theurl)}>全部</a></span& amp; gt;
{pc:get sql=select * from `v9house_type` where `module`='content'}
{loop $data $key $val}
<span {if $_get[typeid] == $val[typeid]}class='shaixuan'{/if}><a href={url_par(price_=$_get[price_]&hstatus=$_get[hstatus]&typeid=$val[typeid]&address=$_get[address],$theurl)}>{$val[name]}</a></span>
{/loop}
{/pc}</p>
<p><span>地区:</span>
<span><a href={url_par(price_=$_get[price_]&hstatus=$_get[hstatus]& typeid=$_get[typeid]&address=,$theurl)}>全部</a></span& amp; gt;
{pc:get sql=select linkageid,name from `v9house_linkage` where parentid=(select linkageid from `v9house_linkage` where name='淄博市')}
{loop $data $key $val}
<span {if $_get[address] == $val[linkageid]}class='shaixuan'{/if}> <a href={url_par(price_=$_get[price_]&hstatus=$_get[hstatus]&typeid=$_get[typeid]&address=$val[linkageid],$theurl)}>{$val[name]}</a></span>
{/loop}
{/pc}</p>
没办法,要想联动,就得每次都传递出所有需要联动的参数,所以url的参数部分就很多,容易晕掉~
获取搜索结果的代码是
共返回 {php echo count($data);} 个结果
放在
{pc:content action=lists where=$where catid=$catid num=25 order=$orderby page=$page}
下面
loop
的上面
共返回 {php echo count($data);} 个结果
排序的参数也很麻烦
<a href='{url_par(price_=$_get[price_]&area_=$_get[area_]& shi=$_get[shi]&typeid=$_get[typeid]&address=$_get[address]& orderby=area_desc,$theurl)}'>面积</a>
基本就这样了,希望有人能看懂
搜索表单也可以直接用在这里
给个例子
<form name=myform1 method=get action=>
<input type=hidden name=m value=content>
<input type=hidden name=c value=index>
<input type=hidden name=a value=lists>
<span><select name=catid>
<option value=6>出售</option>
<option value=12>求购</option>
</select></span>
<span><select name=area_>
<option value=>面积不限</option>
<option value=0-50>小于50</option>
<option value=50-80>50到80</option>
<option value=80-120>80到120</option>
<option value=120-200>120到200</option>
<option value=200-10000>大于200</option>
</select></span>
<span><select name=shi>
<option value=>所有户型</option>
<option value=1>1室</option>
<option value=2>2室</option>
<option value=3>3室</option>
</select></span>
<span><input name=title type=text class=text4 style=width:60px; /></span>
<span><input type=submit value= class=text3 /></span></form>
2025国考·省考课程试听报名