我试图让这个代码进行多个关键字搜索

时间:2014-05-15 13:42:51

标签: php mysql search keyword

当我输入三个或更多关键字时,似乎只搜索最后一个关键字,sydney+region+nsw,它只会搜索nsw

我希望它在输入时搜索多个关键字或完整的搜索字词。

这是代码:

if($_REQUEST['searchkey']!="" && $_REQUEST['searchkey']=="search_record"){
    //Remove any html/javascript.
    $keyword = secureValue($_REQUEST['keyword']);    
    $cat_id = intval($_REQUEST['cat_level_root']);  
    $subcat_id = intval($_REQUEST['cat_level_one']);    
    $sub_subcat_id = intval($_REQUEST['cat_level_two']);
    $stateId = intval($_REQUEST['classi_state']);
    $hometownId = intval($_REQUEST['classi_zipcode']);
    $servicesId = intval($_REQUEST['classified_desc9']);
    $cityId = intval($_REQUEST['classi_city']);
    $priceId = intval($_REQUEST['classified_title9']);
    $ad_key = intval($_REQUEST['ad_id']);

    $types = array();
    $types_x = explode(" ",$keyword);
    $keyword = trim($_REQUEST['keyword']);
    foreach($types_x as $keyword) {
        $x++;
        if($x==0)
            $types[]=($keyword!="" && $keyword!="Enter Your Keywords..") ? " " : ""; 
    }
    $types=implode($types);
    $columns = "SELECT SQL_CALC_FOUND_ROWS *  ";
    $sql = " FROM tbl_classified
        WHERE  clsd_sub_subcat_id=1395 AND CONCAT(classified_title, ' ', 
            classified_desc, '   ',  classified_type6, ' ', classified_title2, ' ",
            classified_type, ' ', classified_type2, ' ', classified_type3, ' ', 
            classified_desc3, ' ', classified_type5) LIKE '%$keyword%' 
            and classified_status='Active' 
            and paid_status!='Pending' 
        ORDER BY classified_post_date,classified_featured asc $types";
    $sql = $columns.$sql;
    $rs_classi=db_query($sql);
    $res_classi = mysql_fetch_array(db_query("Select FOUND_ROWS() as total"));
    $reccnt=$res_classi['total'];
}

1 个答案:

答案 0 :(得分:0)

您使用空格分解关键字字符串。 $types_x = explode(" ",$keyword);

爆炸时使用+(例如explode("+", $keyword))或在爆炸前使用urldecode