PHP PDO MySQL query LIKE -> multiple keywords

后端 未结 3 1145
清酒与你
清酒与你 2020-12-04 04:06

I have a users table in MySQL and would like a search by name. Right now I have the following code:



        
3条回答
  •  爱一瞬间的悲伤
    2020-12-04 04:29

    Please check the below code.

     0){
     $query .= " WHERE "
     for($i=0 ; $i < $split_words; $i++){
       $query .= " name LIKE ? OR ";
     }
     $query = substr($query , 0, -3); //Remove last 3 characters OR with space
    
    
     array_walk($split_words,"addPercentage");
    
     $query->execute($split_words);
    }else{
     $query->execute();
    }
    
    $result = $query->rowCount();
    echo $result;
    
    function addPercentage(&$value,$key)
    {
      $value = "%".$value."%" ;
    }
    ?>
    

提交回复
热议问题