Answer the question
In order to leave comments, you need to log in
How to paginate posts in php?
There is a script for displaying news, but they are all displayed at once, how to make them appear on pages, for example, so that there would be no more than 10 news on each page.
output script:
$page = $_GET['page'];
if (!isset($page)) {
$command = mysqli_query($connection, "SELECT * FROM `news` ORDER BY ID DESC");
require 'pages/news.php';
}
<div class="newsName">Последние новости</div>
<?php
$empn = mysqli_num_rows($command);
if ($empn == 0) {
echo "<div class='empn'>Новостей на данный момент нет! Следите за обновлениями.</div>";
} else {
foreach ($command as $key => $itm):
$valdesc = iconv_strlen($itm['desc']);
$text = mb_substr($itm['desc'],0,1069, 'UTF-8');
$textt = $text . "...";
?>
<div class="news">
<div class="newsZak"><a href="?page=news&id=<?php echo $itm['id']; ?>"><?php echo $itm['name']; ?></a></div>
<div class="newsDate"><?php echo $itm['date']; ?></div>
<div class="newsLine"></div>
<div class="newsDesc"><?php if ($valdesc > 1069) {
echo $textt;
} else {
echo $text;
} ?></div>
<?php
if ($valdesc > 1069) {
?>
<a class="NewsPod" href="?page=news&id=<?php echo $itm['id']; ?>">Открыть полностью</a>
<?php
}
?>
</div>
<?php
endforeach;
}
?>
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