Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Affichage des descriptions + nom de cours :D </title>
  5.     <meta charset="UTF-8">
  6. </head>
  7. <body>
  8. <form>
  9.     <label>Quantité de truc : </label><input type="number" name="quantite_description"></input>
  10.     <select name="classement">
  11.         <option value="ASC">Ascendant par nom</option>
  12.         <option value="DESC">Descendant par nom</option>
  13.     </select>
  14.     <input type="submit"></input>
  15. </form>
  16. <a href="descriptions.php?quantite_description=3">Quantité 3</a>
  17. <a href="descriptions.php?quantite_description=1">Quantité 1</a>
  18. <?php
  19.  
  20.     //Variabiliser les informations de connexion pour réutilisation
  21.     $sql = mysqli_connect('localhost','root','root', 'cours');
  22.  
  23.     //Vérification que les informations de connexion sont fonctionnelles
  24.     if(!$sql){
  25.         echo "OH MY GAWD";
  26.     }
  27.  
  28.     //Stocker dans la variable notre requête SQL pour généraliser la requête
  29.     //$requete = "SELECT nom,description FROM liste LIMIT 5";
  30.  
  31.     //$requete = "SELECT nom,description,nb_heures FROM liste ORDER BY nb_heures DESC LIMIT 2";
  32.  
  33.     //$requete = "SELECT nom,description,nb_heures FROM liste WHERE prerequis = 0 ORDER BY nom";
  34.     if($_GET['quantite_description']){
  35.         $bob = $_GET['quantite_description'];
  36.     }
  37.     else{
  38.         $bob = 5;
  39.     }
  40.  
  41.     if($_GET['classement']){
  42.         $requete = "SELECT nom,description,nb_heures FROM liste ORDER BY nom " . $_GET['classement'] . " LIMIT " . $bob;
  43.     }
  44.     else{
  45.         $requete = "SELECT nom,description,nb_heures FROM liste LIMIT " . $bob;
  46.     }
  47.  
  48.     //Création d'une requete bouclée pour réutilisation dans la boucle
  49.     $requete_boucle = mysqli_query($sql, $requete);
  50.  
  51.     //Création de la boucle pour afficher le contenu du tableau
  52.     while($rangee = mysqli_fetch_assoc($requete_boucle)){
  53.         /*
  54.         echo "<h2>" . utf8_encode($rangee['nom']) . "</h2>";
  55.         echo "<p>";
  56.         echo "<strong>" . $rangee['nb_heures'] . " heures</strong> ";
  57.         echo utf8_encode($rangee['description']);
  58.         echo "</p>";
  59.         */
  60.         $texte = "<h2> %s </h2> <p> <strong> %s heures</strong> %s </p>";
  61.         $text = "<h2> %s </h2> <p> <strong> %s hours</strong> %s </p>";
  62.         $nom = utf8_encode($rangee['nom']);
  63.         $nb_heures = utf8_encode($rangee['nb_heures']);
  64.         $description = utf8_encode($rangee['description']);
  65.         echo sprintf($texte, $nom, $nb_heures, $description);
  66.     }
  67.  
  68.     /*
  69.     W0 = Premiere rangée de ma table = if($rangee) = true
  70.     W1 = 2e rangée = if($rangee) = true
  71.     W2 = 3e rangée = if($rangee) = true
  72.     W3 = 4e rangée = if($rangee) = true
  73.     W4 = 5e rangée = if($rangee) = true
  74.     W5 = NULL = if($rangee) = false
  75.     */
  76. ?>
  77.  
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement