phpcms v9教程 聯(lián)動搜索在房地產(chǎn)網(wǎng)站開發(fā)中的應(yīng)用

字號:


    開發(fā)簡述:使用phpcms V9系統(tǒng),修改源文件5個,創(chuàng)建模型:樓盤、出售、出租、中介、小區(qū),增加聯(lián)動菜單:樓盤,增加用戶組:房產(chǎn)中介。
    實現(xiàn)功能:
    游客發(fā)布信息、會員申請中介、樓盤全方位展示、報名團購、看房功能,發(fā)布信息時可根據(jù)登陸后的會員資料自動填好聯(lián)系信息,中介有自己的店鋪,可給中介留言,聯(lián)動篩選搜索、排序,房源對比功能。
    聯(lián)動篩選搜索功能的實現(xiàn)方法及代碼:
    要修改的文件就是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";
    ?>
    用這段代碼來構(gòu)造查詢條件和排序方式,有了這段代碼之后,要把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>狀態(tài):</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>地區(qū):</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>
    沒辦法,要想聯(lián)動,就得每次都傳遞出所有需要聯(lián)動的參數(shù),所以url的參數(shù)部分就很多,容易暈掉~
    獲取搜索結(jié)果的代碼是
    共返回 {php echo count($data);} 個結(jié)果
    放在
    {pc:content action="lists" where="$where" catid="$catid" num="25" order="$orderby" page="$page"}
    下面
    loop
    的上面
    共返回 {php echo count($data);} 個結(jié)果
    排序的參數(shù)也很麻煩
    <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" /></span>
    <span><input type="submit" value="" /></span></form>