Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <meta charset="utf-8">
  4.     <title>news</title>
  5.     <link rel="stylesheet" type="text/css" href="main.css">
  6. </head>
  7. <body>
  8.     <div class="container">
  9.         <div class="title"><h2>Новости</h2></div>
  10.         <?php require_once 'database.php';
  11.             $itemsPerPage = 5; // количество новостей на странице
  12.            
  13.             // если есть гет параметр page
  14.             if (isset($GET['page'])) {
  15.                 // узнать количество новостей всего и записать в переменную("select count(id) from news")
  16.                 $currentPage = intval($GET['page']); //текущая страница
  17.                
  18.                 $offset = ( $currentPage != 0 ) ?  ($currentPage - 1 ) * $itemsPerPage : 0 ; // отступ для страниц
  19.                 $sql = "SELECT *
  20.                        FROM news
  21.                        LIMIT" . $itemsPerPage . "
  22.                        ORDER BY `idate` DESC
  23.                        OFFSET " . $offset"
  24.            } else {
  25.                $sql = "SELECT * FROM `news` ORDER BY `idate` DESC LIMIT " . $itemsPerPage;
  26.            }  
  27.  
  28.            $sql = mysqli_query($link, $sql);
  29.            $link->close;
  30.            
  31.            while($result = mysqli_fetch_array($sql)):
  32.  
  33.        ?>
  34.  
  35.              
  36.            <div class="date"><?=date('d.m.Y',$result['idate']) ?></div>      
  37.            <span class="link"><a href="view.php?title=<?=$result['title']?>"><?=$result['title'] ?></a></span>
  38.             <div class="announce"><?=$result['announce'] ?></div>
  39.            
  40.            
  41.  
  42.         <?php endwhile ?>  
  43.      
  44.     </div>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement