kalyan
Продвинутый
Дата регистрации:
22.07.2012 17:02:42
Сообщений: 61
<?php
function search($words){
$words = htmlspecialchars($words);
if ($words === "" return false;
$query_search = "";
$arraywords = explode(" ", $words);
foreach($arraywords as $key => $value){
if (isset($arraywords[$key - 1]))
$query_search .= ' OR ';
$query_search .= '`title` LIKE "%'.$value.'%" OR `text` LIKE "%'.$value.'%"';
}
$query = "SELECT * FROM search WHERE $guery_search";
$mysqli = new mysqli ("localhost", "admin","","mediaotbor"
$result_set = $mysqli->query($query);
$mysqli->close();
$i = 0;
while($row = $result_set->fetch_assoc()){
$results[$i] = $row;
$i++;
}
return $results;
}
if(isset($_POST['bsearch'])){
$words = $_POST['words'];
$results = search($words);
}
?>
<html>
<body>
<head>
<title></title>
</head>
<div class="search">
<h4>Поиск по сайту:</h4>
<form name="search" action="copy_file.php" method="post">
<table>
<tr>
<td class="search_td">
<input type="text" name="words" />
</td>
<td>
<input type="submit" name="bsearch" value= "поиск" />
</td>
</tr>
</table>
</form>
<?php
if (isset($_POST['bsearch'])){
echo "<h2>Результат поиска</h2>";
if ($results === false) echo " Пустой запрос";
if (count($results) == 0) echo "Ни чего не найдено";
else
for($i=0; $i<count($results); $i++)
echo $results[$i]['title']."<br />";
?>
</div>
<body>
</html>