Nikita
Освоившийся
Дата регистрации:
06.06.2012 22:12:07
Сообщений: 36
<div style="text-align: center;">
<form action="search.php" method="get" name="form_s">
<input class="search_input_text" name="result" type="text" size="30" maxlength="40" placeholder="Поиск Статьи..."/>
<input class="search_input_submit" name="submit_search" type="image" src="img/search/search_submit.jpg"/>
</form>
</div>
<?php
error_reporting(NULL);
if (isset($_GET['result'])) {
$searchs = mysql_escape_string(strip_tags(trim($_GET['result'])));
$errors = array();
if (empty($result)) {
$errors[] = '<p>Введите поисковой запрос!</p>';
} else if (strlen ($result) < 3) {
$errors[] = '<p>Запрос должен быть более 3 символов!</p>';
}
if (empty($errors)) {
//Обработка запроса
$returned_results = array();
$where = "";
$result = preg_split("/[\s]+/", $result);
$total_search = count($result);
foreach ($result as $key => $search) {
$where .= "text LIKE '%$search%'";
if ($key != ($total_search - 1)) {
$where .= " OR ";
}
}
$tableName="articles";
$targetpage = "articles.php";
$limit = 3;
$query = "SELECT COUNT(*) as num FROM $tableName WHERE $where";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
$results_result = "SELECT * FROM $tableName WHERE $where ORDER BY id DESC LIMIT $start, $limit ";
$results_result = mysql_query($results_result);
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>Предыдущая</a>";
}else{
$paginate.= "<span class='disabled'>Предыдущая</span>"; }
if ($lastpage < 7 + ($stages * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2))
{
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?page=$counter&$result'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='search.php?page=$LastPagem1&$result'>$LastPagem1</a>";
$paginate.= "<a href='search.php?page=$lastpage&$result'>$lastpage</a>";
}
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='search.php?page=1&$result'>1</a>";
$paginate.= "<a href='search.php?page=2&$result'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?page=$counter&$result'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='search.php?page=$LastPagem1&$result'>$LastPagem1</a>";
$paginate.= "<a href='search.php?page=$lastpage&$result'>$lastpage</a>";
}
else
{
$paginate.= "<a href='search.php?page=1&$result'>1</a>";
$paginate.= "<a href='search.php?page=2&$result'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='search.php?page=$counter&$result'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='search.php?page=$next&$search'>Следущая</a>";
}else{
$paginate.= "<span class='disabled'>Следущая</span>";
}
$paginate.= "</div>";
}
if (mysql_num_rows($results_result) > 0) {
$results_num = mysql_num_rows($results_result);
echo "<p style = 'margin-left: 30px;'>По Вашему Запросу <span style = 'color: #F78D1D; font-weight: bold;'>" . $_GET['result'] . "</span> Найдено <span style = 'color: #F78D1D; font-weight: bold;'>" . $results_num . "</span> Совпадений:</p>";
echo ('<br>');
echo ('<br>');
echo $paginate;
echo ('<br>');
echo ('<br>');
$myrow_result = mysql_fetch_array($results_result);
do {
printf("<table align='center' class='news_site'>
<tr>
<td><p class='news_site_title'><a href='articles_str.php?id=%s'>%s</a></p></td>
</tr>
<tr>
<td><p class='news_site_description'>%s</p><p class='news_site_bottom'>Дата: %s | Добавил: %s | Просмотров: %s | Коментарии: 4</p></td>
</tr>
</table><br><br>
", $myrow_result["id"], $myrow_result["title"], $myrow_result["description"], $myrow_result["date"], $myrow_result["author"], $myrow_result["view"]);
} while ($myrow_result = mysql_fetch_array($results_result));
} else {
echo '<p>По Вашему Запросу <span style="color: #F78D1D; font-weight: bold;">' . $_POST['result'] . '</span> Ничего Не Найдено!</p>';
}
} else {
foreach ($errors as $error) {
echo $error, '<br />';
}
}
}
?>
Вопросс:
Как убрать у браузерной строки при рузультате поиска что-бы не выдавало в конце
submit_search.x=0&submit_search.y=0
Пример: Набираю PHP В ПОИСКЕ, В РЕЗУЛЬТАТЕ ВЫДАЕТ В БРАУЗЕРНОЙ СТРОКЕ:
http://localhost/site.ru/search.php?result=PHP&submit_search.x=0&submit_search.y=0