If one searches for vienna university
, my script looks for the presence of vienna
and university
in some MySQL columns.
Now, I want to modify it in the following manner: If the query contains multiple words starting and ending with quotation marks (e.g. "vienna university"
), the script should not separate the words, but rather search for the exact match of vienna university
in the database.
And if the query is Meyer "vienna university"
, the script should search for the presence of Meyer
and vienna university
in the MySQL table.
Would you know how to make this happen?
My code so far:
<?php
$search_keyword = $_GET['query'];
//multiple keywords
$search_keyword = preg_split('/[\s]+/', $search_keyword);
$totalKeywords = count($search_keyword);
$sql = "SELECT * FROM `editors`
WHERE CONCAT_WS(`journal`, `editor`, `affiliation`)
LIKE ?";
//...for multiple keywords
for($i=1 ; $i < $totalKeywords; $i++){
$sql .= " AND CONCAT_WS(`journal`, `editor`, `affiliation`)
LIKE ?";
}
?>