Mysql
 sql >> Database >  >> RDS >> Mysql

PHP mysql query giudica e non fa eco alla parte ripetuta

$sentence = "Marc Gasol is the brother of Pau Gasol";
$words = preg_split("/\s+/", $sentence);

//this will uniqueify your value set
$uniqueWords = array_keys(array_flip($words));

foreach($uniqueWords as $word){
    $parts[] = "name like '%".mysql_real_escape_string($word)."%'";  
}

$where = implode(" OR ", $parts);




$query = mysql_query("SELECT * FROM books WHERE $where "); 
$i = 0;
while($row = mysql_fetch_array($query)) {     
echo $row['name'][$i];     
$i++; 
}