Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Affichage des descriptions + nom de cours :D </title>
- <meta charset="UTF-8">
- </head>
- <body>
- <form>
- <label>Quantité de truc : </label><input type="number" name="quantite_description"></input>
- <select name="classement">
- <option value="ASC">Ascendant par nom</option>
- <option value="DESC">Descendant par nom</option>
- </select>
- <input type="submit"></input>
- </form>
- <a href="descriptions.php?quantite_description=3">Quantité 3</a>
- <a href="descriptions.php?quantite_description=1">Quantité 1</a>
- <?php
- //Variabiliser les informations de connexion pour réutilisation
- $sql = mysqli_connect('localhost','root','root', 'cours');
- //Vérification que les informations de connexion sont fonctionnelles
- if(!$sql){
- echo "OH MY GAWD";
- }
- //Stocker dans la variable notre requête SQL pour généraliser la requête
- //$requete = "SELECT nom,description FROM liste LIMIT 5";
- //$requete = "SELECT nom,description,nb_heures FROM liste ORDER BY nb_heures DESC LIMIT 2";
- //$requete = "SELECT nom,description,nb_heures FROM liste WHERE prerequis = 0 ORDER BY nom";
- if($_GET['quantite_description']){
- $bob = $_GET['quantite_description'];
- }
- else{
- $bob = 5;
- }
- if($_GET['classement']){
- $requete = "SELECT nom,description,nb_heures FROM liste ORDER BY nom " . $_GET['classement'] . " LIMIT " . $bob;
- }
- else{
- $requete = "SELECT nom,description,nb_heures FROM liste LIMIT " . $bob;
- }
- //Création d'une requete bouclée pour réutilisation dans la boucle
- $requete_boucle = mysqli_query($sql, $requete);
- //Création de la boucle pour afficher le contenu du tableau
- while($rangee = mysqli_fetch_assoc($requete_boucle)){
- /*
- echo "<h2>" . utf8_encode($rangee['nom']) . "</h2>";
- echo "<p>";
- echo "<strong>" . $rangee['nb_heures'] . " heures</strong> ";
- echo utf8_encode($rangee['description']);
- echo "</p>";
- */
- $texte = "<h2> %s </h2> <p> <strong> %s heures</strong> %s </p>";
- $text = "<h2> %s </h2> <p> <strong> %s hours</strong> %s </p>";
- $nom = utf8_encode($rangee['nom']);
- $nb_heures = utf8_encode($rangee['nb_heures']);
- $description = utf8_encode($rangee['description']);
- echo sprintf($texte, $nom, $nb_heures, $description);
- }
- /*
- W0 = Premiere rangée de ma table = if($rangee) = true
- W1 = 2e rangée = if($rangee) = true
- W2 = 3e rangée = if($rangee) = true
- W3 = 4e rangée = if($rangee) = true
- W4 = 5e rangée = if($rangee) = true
- W5 = NULL = if($rangee) = false
- */
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement