Answer the question
In order to leave comments, you need to log in
Can't figure out the page switcher for news?
Good evening, comrades! The problem is the following, there is enough news so as not to throw out everything, I made a conclusion of the first 5 news, but then I had to switch the news using the pageselector, which for some reason does not work for me. when you click on 1/2/3, url/news/main/page/3 and 404 crashes.
URL structure: url/page/module
First connected pages
else if ($Page == 'news') {
if (!$Module or $Page == 'news' and $Module == 'category' or $Page == 'news' and $Module == 'main') include('module/news/main.php');
else if ($Module == 'material') include('module/news/material.php');
<?php
if ($Module == 'category' and $_GET['id'] != 1 and $_GET['id'] != 2 and $_GET['id'] != 3) MessageSend(1, 'Такой категории не существует.', '/news');
$_GET['page'] += 0;
Head('Новости');
?>
<body>
<div id="wrapper">
<?php Menu();
MessageShow()?>
<?php
if ($_SESSION['USER_GROUP'] == 2) echo '<a href="/news/add"><div class="button15">Добавить новость</a></div>'
?>
<?php
if (!$Module or $Module == 'main') {
$Param1 = 'SELECT `id`, `name`, `added`, `date` FROM `news` ORDER BY `id` DESC LIMIT 0, 5';
$Param2 = 'SELECT `id`, `name`, `added`, `date`, FROM `news` ORDER BY `id` DESC LIMIT START, 5';
$Param3 = 'SELECT COUNT(`id`) FROM `news`';
$Param4 = '/news/main/page/';
} else if ($Module == 'category') {
$Param1 = 'SELECT `id`, `name`, `added`, `date` FROM `news` WHERE `cat` = '.$_GET['id'].' ORDER BY `id` DESC LIMIT 0, 5';
$Param2 = 'SELECT `id`, `name`, `added`, `date`, `active` FROM `news` WHERE `cat` = '.$_GET['id'].' ORDER BY `id` DESC LIMIT START, 5';
$Param3 = 'SELECT COUNT(`id`) FROM `news` WHERE `cat` = '.$_GET['id'];
$Param4 = '/news/category/?id='.$_GET['id'].'/page/';
}
$Count = mysqli_fetch_row(mysqli_query($CONNECT, $Param3));
if (!$_GET['page']) {
$_GET['page'] = 1;
$Result = mysqli_query($CONNECT, $Param1);
} else {
$Start = ($_GET['page'] - 1) * 5;
$Result = mysqli_query($CONNECT, str_replace('START', $Start, $Param2));
}
PageSelector($Param4, $_GET['page'], $Count);
while ($Row = mysqli_fetch_assoc($Result)) echo '<a href="/news/material/?id='.$Row['id'].'"><div class="NewsBlock"><span>'.$Row['name'].'</span><br>Добавил: '.$Row['added'].' | '.$Row['date'].'</a> </div>';
?>
</div>
<?php
$_GET['id'] += 0;
if ($_GET['id'] == 0) MessageSend(1, 'URL адрес указан неверно.', '/news');
$Row = mysqli_fetch_assoc(mysqli_query($CONNECT, 'SELECT `name`, `added`, `date`, `read`, `text` FROM `news` WHERE `id` = '.$_GET['id']));
if (!$Row['name']) MessageSend(1, 'Такой новости не существует.', '/news');
mysqli_query($CONNECT, 'UPDATE `news` SET `read` = `read` + 1 WHERE `id` = '.$_GET['id']);
Head($Row['name']);
?>
<body>
<div id="wrapper">
<?php Menu();
MessageShow()?>
<?php
if ($_SESSION['USER_GROUP'] == 2) $EDIT = '| <a href="/news/edit/?id='.$_GET['id'].'">Редактировать новость</a> | <a href="/news/delete/?id='.$_GET['id'].'">Удалить новость</a>';
echo '<div class="gucci">'.$Row['name'].'<br><br>'.$Row['text'].'<br><br> Просмотров: '.($Row['read'] + 1).' | Добавил: '.$Row['added'].' | Дата: '.$Row['date'].' '.$EDIT.' </div>';
?>
function PageSelector($p1, $p2, $p3, $p4 = 5) {
/*
$p1 - URL (Например: /news/main/page)
$p2 - Текущая страница (из $Param['page'])
$p3 - Кол-во новостей
$p4 - Кол-во записей на странице
*/
$Page = ceil($p3[0] / $p4); //делим кол-во новостей на кол-во записей на странице.
if ($Page > 1) { //А нужен ли переключатель?
echo '<div class="PageSelector">';
for($i = ($p2 - 3); $i < ($Page + 1); $i++) {
if ($i > 0 and $i <= ($p2 + 3)) {
if ($p2 == $i) $Swch = 'SwchItemCur';
else $Swch = 'SwchItem';
echo '<a class="'.$Swch.'" href="'.$p1.$i.'">'.$i.'</a>';
}
}
echo '</div>';
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question