Blogger Information
Blog 263
fans 3
comment 2
visits 113374
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模糊查询多条件多字段加亮处理
福哥的博客
Original
895 people have browsed it
<?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']);
     }
?>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post