Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try
- {
- $bdd = new PDO('mysql:host=localhost;dbname=blog', 'root', '');
- }
- catch (Exeption $e)
- {
- die('Erreur :' .$e->getMessage());
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" />
- <title>Blog T.A games studio</title>
- <link rel="stylesheet" href="styleblog.css" />
- </head>
- <body>
- <div id="blocpage">
- <h1>Liste des News : </h1>
- <hr/>
- <?php
- //Articles par page MAX
- $articlesParPage = 3;
- // Compte nb article
- $req = $bdd->query('SELECT COUNT(*) AS total FROM articles');
- $donnees = $req->fetch();
- $total = $donnees['total'];
- //compte nb page à générer
- $nbDePages = ceil($total/$articlesParPage);
- $pageActuelle = 1;
- //changer page (URL)
- if(isset($_GET['page']) AND !empty($_GET['page']))
- {
- $pageAcuelle = intval($_GET['page']);
- // Si page n'existe pas
- if($pageActuelle > $nbDePages) {
- $pageActuelle = $nbDePages;
- }
- }
- $article1erARecup = ($pageActuelle-1)*$articlesParPage;
- $req_articles= $bdd->query('SELECT * FROM articles ORDER BY id DESC LIMIT '.$article1erARecup.', '.$articlesParPage.'');
- while($donnees_articles = $req_articles->fetch()) {
- ?>
- <div class="news">
- <?php
- echo 'News nº ' .$donnees_articles['id'] .' : <br/>' ;
- ?><a href="post.php?id=<?php echo $donnees_articles['id'] ?>">
- <?php
- echo '<h3>' .strip_tags($donnees_articles['titre']) .'</h3> </a>';
- echo '<p>' .nl2br($donnees_articles['contenu']) .'</p>' .'<br/>';
- echo '<em> ecrit par : ' .strip_tags($donnees_articles['auteur']) .'</em>';
- ?>
- <hr/>
- </div>
- <?php
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement