<?php
$_POST["word"] = trim($_POST["word"]); $_GET["word"] = trim(strtolower($_GET["word"])); $catid="40"; // id категории, которую показываем, категории сонника // псевдонимы раздела и категории $razdel = 'chepuha'; $category = 'sonnik';
// здесь принято, что псевдоним скрипта sonnik $p = $_GET["p"]; // номер страницы if (!$p) { $p = '1'; } // если страница не выбрана, то показываем первую $cnt = 10; // количество показываемых объектов на странице
$start = $p * $cnt - 1;
if ($_GET["word"] and !$_POST["word"]) {
$query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and lower(a.title) LIKE "'.$_GET["word"].'%"'; $result = mysql_query($query) or die('Ошибка выполнения запроса1.'); $total = mysql_num_rows($result);
if ($p==1) { $query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and lower(a.title) LIKE "'.$_GET["word"].'%" ORDER BY a.id ASC LIMIT 0, '.$cnt; $res = mysql_query($query) or die('Ошибка выполнения запроса1.'); } else { $query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and lower(a.title) LIKE "'.$_GET["word"].'%" ORDER BY a.id ASC LIMIT '.$start.', '.$cnt; $res = mysql_query($query) or die('Ошибка выполнения запроса2.'); }
while ($row = mysql_fetch_assoc($res)) { // показываем данные if ($row["alias"]) { echo '<div align="left"> <div align="left" style="padding: 10px; border-bottom: 1px dashed #999999; width: 600px;"><a href="/"HTTP_HOST"].'/'. $razdel.'/'.$category.'/'.$row["id"].'-'.$row["alias"].'.html">'.$row["title"].'</a></div> </div>'; } else { echo '<div align="left"> <div align="left" style="padding: 10px; border-bottom: 1px dashed #999999; width: 600px;"><a href="/"HTTP_HOST"].'/index.php?option=com_content&view=article&id='.$row["id"].'">'.$row["title"].'</a></div> </div>'; } }
}
if ($_POST["word"]) {
/* if ($p=1) { $query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and lower(a.fulltext) LIKE "%'.$_POST["word"].'%" ORDER BY a.id ASC LIMIT 0, '.$cnt; $res = mysql_query($query) or die('Ошибка выполнения запроса3.'); } else { $query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and lower(a.fulltext) LIKE "%'.$_POST["word"].'%" ORDER BY a.id ASC LIMIT '.$start.', '.$cnt; $res = mysql_query($query) or die('Ошибка выполнения запроса4.'); }
$total = mysql_num_rows($res); */
$query = 'SELECT * FROM jos_content as a WHERE a.catid="'.$catid.'" and (a.title LIKE "%'.$_POST["word"].'%" or a.fulltext LIKE "%'.$_POST["word"].'%") ORDER BY a.id ASC'; $res = mysql_query($query) or die('Ошибка выполнения запроса3.');
while ($row = mysql_fetch_assoc($res)) { // показываем данные
if ($row["alias"]) { echo '<div align="left"> <div align="left" style="padding: 10px; border-bottom: 1px dashed #999999; width: 600px;"><a href="/"HTTP_HOST"].'/'.$razdel.'/'.$category.'/'.$row["id"].'-'.$row["alias"].'.html">'.$row["title"].'</a></div> </div>'; } else { echo '<div align="left"> <div align="left" style="padding: 10px; border-bottom: 1px dashed #999999; width: 600px;"><a href="/"HTTP_HOST"].'/index.php?option=com_content&view=article&id='.$row["id"].'">'.$row["title"].'</a></div> </div>'; } }
}
if ($total>$cnt and $_GET["word"] and !$_POST["word"]) {
$pages = ceil($total/$cnt)-1; // количество страниц
echo '<div align="center" style="margin-top: 10px; width: 600px;">Страницы: ';
for ($i=1; $i<=$pages; $i++) {
if ($p==$i) { echo '<b>['.$i.']</b> '; } else { // проблема со ссылкой echo '<a href="/chepuha/sonnik.html?&p='.$i.'&word='.$_GET["word"].'">'.$i.'</a> '; }
}
echo '</div>';
}
?>
|