Advertisement
Guest User

php_forum

a guest
Mar 1st, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.37 KB | None | 0 0
  1. <?php //Cette fonction doit être appelée avant tout code html
  2. session_start();
  3. //On donne ensuite un titre à la page, puis on appelle notre fichier debut.php
  4. $titre = "Index du forum";
  5. include("identifiants.php");
  6. include("debut.php");
  7. include("menu.php");
  8. ?>
  9.  
  10. <?php //fil d'ariane
  11. echo'<i>Vous êtes ici : </i><a href ="./index.php">Index du forum</a>';
  12. ?>
  13.  
  14. <h1>Mon super forum</h1>
  15. <?php //Initialisation de deux variables
  16. $totaldesmessages = 0;
  17. $categorie = NULL;
  18. ?>
  19.  
  20. <?php //Cette requête permet d'obtenir tout sur le forum
  21. $query=$db->prepare('SELECT cat_id, cat_nom,
  22. forum_forum.forum_id, forum_name, forum_desc, forum_post, forum_topic, auth_view, forum_topic.topic_id,  forum_topic.topic_post, post_id, post_time, post_createur, membre_pseudo,
  23. membre_id
  24. FROM forum_categorie
  25. LEFT JOIN forum_forum ON forum_categorie.cat_id = forum_forum.forum_cat_id
  26. LEFT JOIN forum_post ON forum_post.post_id = forum_forum.forum_last_post_id
  27. LEFT JOIN forum_topic ON forum_topic.topic_id = forum_post.topic_id
  28. LEFT JOIN forum_membres ON forum_membres.membre_id = forum_post.post_createur
  29. WHERE auth_view <= :lvl
  30. ORDER BY cat_ordre, forum_ordre DESC');
  31. $query->bindValue(':lvl',$lvl,PDO::PARAM_INT);
  32. $query->execute();
  33. ?>
  34.  
  35. <table>
  36. <?php //Début de la boucle
  37. while($data = $query->fetch())
  38. {
  39.     //On affiche chaque catégorie
  40.     if( $categorie != $data['cat_id'] )
  41.     {
  42.         //Si c'est une nouvelle catégorie on l'affiche
  43.         $categorie = $data['cat_id'];
  44.  ?>
  45.         <tr>
  46.         <th></th>
  47.         <th class="titre"><strong><?php echo stripslashes(htmlspecialchars($data['cat_nom'])); ?>
  48.         </strong></th>            
  49.         <th class="nombremessages"><strong>Sujets</strong></th>      
  50.         <th class="nombresujets"><strong>Messages</strong></th>      
  51.         <th class="derniermessage"><strong>Dernier message</strong></th>  
  52.         </tr>
  53.         <?php              
  54.     }
  55.     //Ici, on met le contenu de chaque catégorie
  56.     <?php //affichage
  57.     // Ce super echo de la mort affiche tous
  58.     // les forums en détail : description, nombre de réponses etc...
  59.     echo'<tr><td><img src="./images/message.gif" alt="message" /></td>
  60.  
  61.    <td class="titre"><strong>
  62.    <a href="./voirforum.php?f='.$data['forum_id'].'">
  63.    '.stripslashes(htmlspecialchars($data['forum_name'])).'</a></strong>
  64.    <br />'.nl2br(stripslashes(htmlspecialchars($data['forum_desc']))).'</td>
  65.    <td class="nombresujets">'.$data['forum_topic'].'</td>
  66.    <td class="nombremessages">'.$data['forum_post'].'</td>';
  67.     // Deux cas possibles :
  68.     // Soit il y a un nouveau message, soit le forum est vide
  69.     if (!empty($data['forum_post']))
  70.     {
  71.          //Selection dernier message
  72.      $nombreDeMessagesParPage = 15;
  73.          $nbr_post = $data['topic_post'] +1;
  74.      $page = ceil($nbr_post / $nombreDeMessagesParPage);
  75.          echo'<td class="derniermessage">
  76.         '.date('H\hi \l\e d/M/Y',$data['post_time']).'<br />
  77.         <a href="./voirprofil.php?m='.stripslashes(htmlspecialchars($data['membre_id'])).'&amp;action=consulter">'.$data['membre_pseudo'].'  </a>
  78.         <a href="./voirtopic.php?t='.$data['topic_id'].'&amp;page='.$page.'#p_'.$data['post_id'].'">
  79.         <img src="./images/go.gif" alt="go" /></a></td></tr>';
  80.      }
  81.      else
  82.      {
  83.          echo'<td class="nombremessages">Pas de message</td></tr>';
  84.      }
  85.      //Cette variable stock le nombre de messages, on la met à jour
  86.      $totaldesmessages += $data['forum_post'];
  87.      //On ferme notre boucle et nos balises
  88. } //fin de la boucle
  89. $query->CloseCursor();
  90. echo '</table></div>';
  91. ?>
  92. }
  93.  
  94. <?php //Le pied de page ici :
  95. echo'<div id="footer">
  96. <h2>
  97. Qui est en ligne ?
  98. </h2>
  99. ';
  100. //On compte les membres
  101. $TotalDesMembres = $db->query('SELECT COUNT(*) FROM forum_membres')->fetchColumn();
  102. $query->CloseCursor();  
  103. $query = $db->query('SELECT membre_pseudo, membre_id FROM forum_membres ORDER BY membre_id DESC LIMIT 0, 1');
  104. $data = $query->fetch();
  105. $derniermembre = stripslashes(htmlspecialchars($data['membre_pseudo']));
  106. echo'<p>Le total des messages du forum est <strong>'.$totaldesmessages.'</strong>.<br />';
  107. echo'Le site et le forum comptent <strong>'.$TotalDesMembres.'</strong> membres.<br />';
  108. echo'Le dernier membre est <a href="./voirprofil.php?m='.$data['membre_id'].'&amp;action=consulter">'.$derniermembre.'</a>.</p>'
  109. $query->CloseCursor();
  110. ?>
  111. </div>
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement