Gloorian

index.php

Jul 30th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.     include('includes/debut.php');
  3.     include('includes/menu.php');
  4.     include('includes/identifiants.php');
  5.  
  6.     echo '<div id="posts">';
  7.    
  8.     $retour_total = $bdd->query('SELECT COUNT(*) AS total FROM post');
  9.     $donnees_total = $retour_total->fetch();
  10.     $total = $donnees_total['total'];
  11.     $retour_total->closeCursor();
  12.    
  13.     $nombreDeMessagesParPages = 5;
  14.     $nombreDePages = ceil($total/$nombreDeMessagesParPages);
  15.    
  16.     if(isset($_GET['page']))
  17.     {
  18.         $page_actuelle = intval($_GET['page']);
  19.        
  20.         if($page_actuelle > $nombreDePages)
  21.         {
  22.             $page_actuelle = $nombreDePages;
  23.         }
  24.     }
  25.     else
  26.     {
  27.         $page_actuelle = 1;
  28.     }
  29.    
  30.     $premiere_entree = ($page_actuelle -1) * $nombreDeMessagesParPages;
  31.    
  32.     $retour_messages = $bdd->prepare('SELECT id, titre, contenu, DATE_FORMAT(date_creation, "%d/%m/%Y %hh%imin") AS date_creation FROM post ORDER BY id DESC LIMIT ?, ?');
  33.     $retour_messages->execute(array($premiere_entree, $nombreDeMessagesParPages));
  34.    
  35.     while($donnees_messages=$retour_messages->fetch())
  36.     {
  37.         echo '<div class="posts"><h2 class="titre">' . $donnees_messages['titre'] . '</h2><br/>
  38.              <h3 class="date">Le ' . $donnees_messages['date_creation'] . '.</h3><br />
  39.              <p class="contenu">' . $donnees_messages['contenu'] . '</p></div><br /><br />';
  40.     }
  41.     $retour_messages->closeCursor();
  42.     echo '<p>Page: ';
  43.     for($i = 1 ; $i <= $nombreDePages ; $i++)
  44.     {
  45.         if($i == $page_actuelle)
  46.         {
  47.             echo ' [ ' . $i . ' ] ';
  48.         }
  49.         else
  50.         {
  51.             echo ' <a href="index.php?page=' . $i . '">' . $i . '</a>';
  52.         }
  53.     }
  54.     echo '</p>';
Advertisement
Add Comment
Please, Sign In to add comment