<?php
$mysqli = db_connect();
if(isset($_GET['go_search'])){
$k=$_GET['search_keyword'];
$k=preg_replace ( "/\s(?=\s)/","\\1", $k );//多个连续空格只保留一个
$k=trim($k);
$k=explode(" ",$k);
if($k[0]!=""){
$city=$_GET['city1'];
//$sql="select*from job where concat(suername,content) like '%$k[0]%' or concat(suername,content) like '%$k[1]%' and city='$city'";
//$sql="select * from job where 1=1";
$sql = "SELECT * FROM (";
if($k){
for($i=0;$i<count($k);$i++) //根据每个搜索关键词构建SQL语句
{
if($i==0){ //对第一个关键词,不使用UNION
$sql .= "select * from job where concat(suername,content) like '%$k[0]%'";
}
else {//对其他关键词,使用UNION连接
$sql .= " union select * from job where concat(suername,content) like
'%$k[$i]%'";
}
}
$sql .=")as a where";
$sql.= " id = '$_GET[id]'";
if($city){
$sql=$sql." and city = '$city'";
}
$sql.= " ORDER BY `a`.`id` DESC";
}
$q=$mysqli->query($sql);
while($row=$q->fetch_array()){
for($i=0;$i<count($k);$i++){
$row['content']=preg_replace("/($k[$i])/i","<font color=red><b>\\1</b></font>",$row['content']);
$row['suername']=preg_replace("/($k[$i])/i","<font color=red><b>\\1</b></font>",$row['suername']);
}
?>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号