Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('includes/debut.php');
- include('includes/menu.php');
- include('includes/identifiants.php');
- echo '<div id="posts">';
- $retour_total = $bdd->query('SELECT COUNT(*) AS total FROM post');
- $donnees_total = $retour_total->fetch();
- $total = $donnees_total['total'];
- $retour_total->closeCursor();
- $nombreDeMessagesParPages = 5;
- $nombreDePages = ceil($total/$nombreDeMessagesParPages);
- if(isset($_GET['page']))
- {
- $page_actuelle = intval($_GET['page']);
- if($page_actuelle > $nombreDePages)
- {
- $page_actuelle = $nombreDePages;
- }
- }
- else
- {
- $page_actuelle = 1;
- }
- $premiere_entree = ($page_actuelle -1) * $nombreDeMessagesParPages;
- $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 ?, ?');
- $retour_messages->execute(array($premiere_entree, $nombreDeMessagesParPages));
- while($donnees_messages=$retour_messages->fetch())
- {
- echo '<div class="posts"><h2 class="titre">' . $donnees_messages['titre'] . '</h2><br/>
- <h3 class="date">Le ' . $donnees_messages['date_creation'] . '.</h3><br />
- <p class="contenu">' . $donnees_messages['contenu'] . '</p></div><br /><br />';
- }
- $retour_messages->closeCursor();
- echo '<p>Page: ';
- for($i = 1 ; $i <= $nombreDePages ; $i++)
- {
- if($i == $page_actuelle)
- {
- echo ' [ ' . $i . ' ] ';
- }
- else
- {
- echo ' <a href="index.php?page=' . $i . '">' . $i . '</a>';
- }
- }
- echo '</p>';
Advertisement
Add Comment
Please, Sign In to add comment