Advertisement
Guest User

Untitled

a guest
Aug 7th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3. try
  4. {
  5. $bdd = new PDO('mysql:host=localhost;dbname=blog', 'root', '');
  6. }
  7. catch (Exeption $e)
  8. {
  9.         die('Erreur :' .$e->getMessage());
  10. }
  11.  
  12.  
  13. ?>
  14. <!DOCTYPE html>
  15. <html>
  16.  
  17.     <head>
  18.         <meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" />
  19.         <title>Blog T.A games studio</title>
  20.         <link rel="stylesheet" href="styleblog.css" />
  21.     </head>
  22.        
  23.         <body>
  24.            
  25.             <div id="blocpage">
  26. <h1>Liste des News : </h1>
  27. <hr/>
  28. <?php
  29. //Articles par page MAX
  30. $articlesParPage = 3;
  31.  
  32. // Compte nb article
  33. $req = $bdd->query('SELECT COUNT(*) AS total FROM articles');
  34. $donnees = $req->fetch();
  35. $total = $donnees['total'];
  36.  
  37. //compte nb page à générer
  38. $nbDePages = ceil($total/$articlesParPage);
  39. $pageActuelle = int;
  40. //changer page (URL)
  41. if(isset($_GET['page']) && preg_match('/^[1-9][0-9]*$/', $_GET['page'])) {
  42.     $pageAcuelle = $_GET['page'];
  43.     // Si page n'existe pas
  44.     if($pageActuelle > $nbDePages)
  45.         $pageActuelle = $nbDePages;
  46. }
  47.  
  48. else
  49. {
  50.     die('Hacking attempt');  
  51. }
  52.  
  53. $article1erARecup = ($pageActuelle-1)*$articlesParPage;
  54. print_r($pageActuelle);
  55. $req_articles= $bdd->query('SELECT * FROM articles ORDER BY id DESC LIMIT '.$article1erARecup.', '.$articlesParPage.'');
  56.  
  57. while($donnees_articles = $req_articles->fetch()) {
  58. ?>
  59. <div class="news">
  60. <?php
  61. echo 'News n&#186; ' .$donnees_articles['id'] .' : <br/>' ;
  62. ?><a href="post.php?id=<?php echo $donnees_articles['id'] ?>">
  63. <?php
  64. echo '<h3>'              .strip_tags($donnees_articles['titre']) .'</h3> </a>';
  65. echo '<p>'               .nl2br($donnees_articles['contenu']) .'</p>' .'<br/>';
  66. echo '<em> ecrit par : ' .strip_tags($donnees_articles['auteur']) .'</em>';
  67. ?>
  68. <hr/>
  69.  
  70. </div>
  71.  
  72.  
  73.  
  74. <?php
  75. }
  76. ?>
  77.     </div>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement