Файл: 4mast/profmas.ru/pages/shop/incfiles/search.php
Строк: 26
<?php
session_start();
define('ROOT', $_SERVER['DOCUMENT_ROOT'].'/');
require_once(ROOT.'includes/Headers.php');
require_once(ROOT.'includes/PDO_func.php');
H('Поиск', '<a href="/pages/shop" style="color:white;">Магазин</a> | <b>Поиск</b>');
echo '<div class="block">';
if (isset($_SESSION['search'])) $search = htmlspecialchars(trim($_SESSION['search']));
if (isset($_POST['search'])) $search = htmlspecialchars(trim($_POST['search']));
$_SESSION['search'] = $search;
if ($_POST['search'] || $search)
{
$count = DB::$dbs->querySingle("SELECT COUNT(id) FROM magazin_file WHERE name LIKE ?", array("%$search%"));
$items_per_page = 10;
$pages = ceil($count/$items_per_page);
$page = (int)$_GET['page'];
if ($page < 1) {
$page = 1;
}
if ($page > $pages) {
$page = $pages;
}
$start = $page * $items_per_page - $items_per_page;
if ($count == 0) {
echo '<div class="error">Поиск не дал результата!</div>';
unset($_SESSION['search']);
}
else {
$sql = DB::$dbs->query("SELECT * FROM magazin_file WHERE name LIKE ? ORDER BY time DESC LIMIT $start, $items_per_page", array("%$search%"));
while($a = $sql -> fetch ()) {
echo '<div class="lst"><a href="/pages/shop/file/'.$a['id'].'">' .$a['name']. '</a> (<b>'.$a['price']. ' р.</b>)</div>';
}
}
if ($pages > 1) {
echo '<div class="lst">' .pages('?'). '</div>';
}
}
echo '<div class="ass"><div class="news">Введите поисковый запрос:<br/><form method="POST" action="?"><input type="text" name="search" value="'.$search.'" /><br/><input type="submit" value="Поиск"/></form></div></div>';
echo '</div>';
require_once(ROOT.'includes/Footers.php');
?>