0
當我鍵入三個關鍵字或更多似乎只搜索最後一個關鍵字,即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'];
}
它有點混淆你在那裏做什麼......在你定義$ sql的時候$關鍵字的價值是什麼?如果我理解正確,您的問題與查詢和輸入的用法有關。另外,你(我想)通過$ keyword = secureValue($ _ REQUEST ['keyword'])來清理輸入內容。然後用原始的post值重新定義它...對於你的sql查詢,我認爲你會比...更好... MATCH ... AGAINST ...參數集。 – alou