Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="utf-8">
- <title>news</title>
- <link rel="stylesheet" type="text/css" href="main.css">
- </head>
- <body>
- <div class="container">
- <div class="title"><h2>Новости</h2></div>
- <?php require_once 'database.php';
- $itemsPerPage = 5; // количество новостей на странице
- // если есть гет параметр page
- if (isset($GET['page'])) {
- // узнать количество новостей всего и записать в переменную("select count(id) from news")
- $currentPage = intval($GET['page']); //текущая страница
- $offset = ( $currentPage != 0 ) ? ($currentPage - 1 ) * $itemsPerPage : 0 ; // отступ для страниц
- $sql = "SELECT *
- FROM news
- LIMIT" . $itemsPerPage . "
- ORDER BY `idate` DESC
- OFFSET " . $offset"
- } else {
- $sql = "SELECT * FROM `news` ORDER BY `idate` DESC LIMIT " . $itemsPerPage;
- }
- $sql = mysqli_query($link, $sql);
- $link->close;
- while($result = mysqli_fetch_array($sql)):
- ?>
- <div class="date"><?=date('d.m.Y',$result['idate']) ?></div>
- <span class="link"><a href="view.php?title=<?=$result['title']?>"><?=$result['title'] ?></a></span>
- <div class="announce"><?=$result['announce'] ?></div>
- <?php endwhile ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement