function search($words) {
$words = htmlspecialchars($words);
if ($words === "") return false;
$query_search = "";
$result1 = "";
$arraywords = explode (" ", $words);
foreach($arraywords as $key => $value) {
if (isset($arraywords[$key -1]))
$query_search .= 'OR';
$query_search .= '`title` LIKE "%'.$value.'%" OR `year` LIKE "%'.$value.'%"';
}
$query = "SELECT * FROM films WHERE $query_search";
$mysqli = new mysqli("localhost","test","parol","test");
$result_set = $mysqli->query($query);
$mysqli->close();
$i = 0;
while($row = $result_set->fetch_assoc()) {
$result1[$i] = $row;
$i++;
}
$result_set->close();
return $result1;
}
if (isset($_POST['bsearch'])) {
$words = $_POST['words'];
$result1 = search($words);
}
$result1 = search($words);
//var_dump(search($words));
if (isset($_POST['bsearch'])) {
if ($result1 === false){
echo "<div style='color:red'>Вы задали пустой запрос</div>";
}
else{
for ($i = 0; $i < count($result); $i++)
echo $result1[$i] ["title"];
}
}
?>