Advertisement
Guest User

Pagination

a guest
Aug 7th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  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 = 1;
  40.  
  41. //changer page (URL)
  42. if(isset($_GET['page']) AND !empty($_GET['page']))
  43. {
  44.  
  45.     $pageAcuelle = intval($_GET['page']);
  46.     // Si page n'existe pas
  47.     if($pageActuelle > $nbDePages) {
  48.  
  49.         $pageActuelle = $nbDePages;
  50.     }
  51.  
  52.  
  53. }
  54.  
  55. $article1erARecup = ($pageActuelle-1)*$articlesParPage;
  56.  
  57. $req_articles= $bdd->query('SELECT * FROM articles ORDER BY id DESC LIMIT '.$article1erARecup.', '.$articlesParPage.'');
  58.  
  59. while($donnees_articles = $req_articles->fetch()) {
  60. ?>
  61. <div class="news">
  62. <?php
  63. echo 'News n&#186; ' .$donnees_articles['id'] .' : <br/>' ;
  64. ?><a href="post.php?id=<?php echo $donnees_articles['id'] ?>">
  65. <?php
  66. echo '<h3>'              .strip_tags($donnees_articles['titre']) .'</h3> </a>';
  67. echo '<p>'               .nl2br($donnees_articles['contenu']) .'</p>' .'<br/>';
  68. echo '<em> ecrit par : ' .strip_tags($donnees_articles['auteur']) .'</em>';
  69. ?>
  70. <hr/>
  71.  
  72. </div>
  73.  
  74.  
  75.  
  76. <?php
  77. }
  78. ?>
  79.     </div>
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement