如何在Search.class.php中按国家/地区搜索?

时间:2014-03-22 00:33:53

标签: php mysql

抱歉,我是PHP / MySQL的新手。在下面的代码中,我如何按国家/地区搜索?我试过更改代码但是我遇到了错误。

由于

echo $this->country; //what I want to search by

    if($bsiCore->config['conf_rental_type'] == 1){

        $searchsql_count = mysql_query("select count(*) from bsi_apartment_master as bam, bsi_appmt_features as baf where  bam.status=true and  baf.appmt_id=bam.appmt_id".$addquery." and baf.bedroom >=".$this->bedroom." and baf.bathroom >=".$this->bathroom." and bam.appmt_id not in (select appmt_id from bsi_bookings WHERE is_deleted = FALSE AND (('".$this->mysqlCheckInDate."' BETWEEN checkin_date AND DATE_SUB(checkout_date, INTERVAL 1 DAY)) OR (DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY) BETWEEN checkin_date AND DATE_SUB(checkout_date, INTERVAL 1 DAY)) OR (checkin_date BETWEEN '".$this->mysqlCheckInDate."' AND DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY)) OR (DATE_SUB(checkout_date, INTERVAL 1 DAY) BETWEEN '".$this->mysqlCheckInDate."' AND DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY))))   ");

        $searchsql = "SELECT pp_id, appmt_id, price, max( stay_from )
                        FROM (
                        SELECT bp.pp_id, bam.appmt_id, bam.appmt_name, bp.price, bp.stay_from
                        FROM bsi_apartment_master AS bam, bsi_appmt_features AS baf, bsi_priceplan AS bp
                        WHERE bam.status=true and baf.appmt_id = bam.appmt_id".$addquery." AND baf.bedroom >=".$this->bedroom." AND baf.bathroom >=".$this->bathroom." 
                        AND bam.appmt_id NOT IN (SELECT appmt_id FROM bsi_bookings WHERE is_deleted = FALSE AND (( '".$this->mysqlCheckInDate."'
                        BETWEEN checkin_date AND checkin_date AND DATE_SUB(checkout_date, INTERVAL 1 DAY) )
                        OR ( DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY) BETWEEN checkin_date AND checkin_date AND DATE_SUB(checkout_date, INTERVAL 1 DAY) )
                        OR ( checkin_date BETWEEN '".$this->mysqlCheckInDate."' AND DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY) )
                        OR ( checkin_date AND DATE_SUB(checkout_date, INTERVAL 1 DAY) BETWEEN '".$this->mysqlCheckInDate."' AND DATE_SUB('".$this->mysqlCheckOutDate."', INTERVAL 1 DAY) )))
                        AND bam.appmt_id = bp.appmt_id
                        AND if( ( ".$staycount." NOT BETWEEN bp.stay_from AND bp.stay_to ) = true, 
                        ( ".$staycount." NOT BETWEEN bp.stay_from AND bp.stay_to ) AND bp.default_pp !=0, 
                        ( ".$staycount." BETWEEN bp.stay_from AND bp.stay_to ) )
                        order by bp.stay_from desc
                        ) AS t1
                        GROUP BY appmt_id
                        order by price ".$this->sorting;

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。在索引页面上,我有以下下拉框:

<select id="country_select" name="country_select" class="home-select">
<?php echo $bsiCore->getCountrycombo();?>
</select>

在Search.class.php中,我刚刚在mysql搜索条件中添加了以下内容:

and bam.country='".mysql_real_escape_string(trim($_POST['country_select']))."'