IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Undefined variable tournois [PHP 7]


Sujet :

Langage PHP

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2019
    Messages
    101
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2019
    Messages : 101
    Par défaut Undefined variable tournois
    Bonjour, j'aimerais une aide sur un exercice en PHP

    Merci d'avance.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
     
    <?php 
     
    $mysqli = new mysqli('localhost', 'root', '', 'ja_tennis');
    $mysqli->set_charset("utf8");
    ?>
     
    <!DOCTYPE html>
     
    <html>
         <head>
              <meta charset="UTF-8">
    		  <title>Accueil</title>
    		  <link rel="stylesheet" type="text/css" href="styles.css">
         </head>
     
         <body>
              <?php
     
    			if (isset($_GET['submit_form'])) {
     
    				if (isset($_GET['annee'])) {
     
    					$annee = $_GET['annee'];
     
    					$result = $mysqli->query('SELECT tournois_id, tournois_nom, tournois_annee, tournois_date FROM tournois');
     
    					while ($row = $result->fetch_array()) {
     
    			        $tournois_id = $row['tournois_id'];
    			        $tournois_nom = $row['tournois_nom'];
    			        $tournois_annee = $row['tournois_annee'];
    			        $tournois_date = $row['tournois_date'];
     
    			        $tournois[$tournois_id]['Nom du tournoi'] = $tournois_nom;
    			        $tournois[$tournois_id]['Année du tournoi'] = $tournois_annee;
    			        $tournois[$tournois_id]['Date du tournoi'] = $tournois_date;
     
    			        }
     
                        echo '<pre>';
    		            print_r($tournois);
    		            echo '</pre>';
    		        }
                }
              ?>
     
    	      <div id="wrapper">
                  <form action="" method="get">
    			       <label>Tournoi par année</label>
     
    				   <select name="annee">
    				          <option type="radio" value="2017">2017</option>
    					      <option type="radio" value="2018">2018</option>
    					      <option type="radio" value="2019" selected="selected">2019</option>
    				   </select>
     
    				   <input type="submit" value="filtrer" name="submit_form">
    			  </form>
     
    			  <table border="1">
    			        <tr>
                           <th>Identifiant</th><th>Nom du tournoi</th><th>Année du tournoi</th><th>Date du tournoi</th>
                        </tr>
     
                        <?php foreach ($tournois as $id => $nom) : ?>
     
                        <tr>
                           <td><?php echo $id; ?></td>
                           <td><?php echo $nom['Nom du tournoi']; ?></td>
                           <td><?php echo $nom['Année du tournoi']; ?></td>
                           <td><?php echo $nom['Date du tournoi']; ?></td>
    			        </tr>
     
    			        <?php endforeach ?>
    			  </table>
              </div>
    	 </body>
    </html>
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    -- phpMyAdmin SQL Dump
    -- version 4.8.4
    -- https://www.phpmyadmin.net/
    --
    -- Hôte : 127.0.0.1:3306
    -- Généré le :  mer. 06 mars 2019 à 12:56
    -- Version du serveur :  5.7.24
    -- Version de PHP :  7.3.1
     
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET AUTOCOMMIT = 0;
    START TRANSACTION;
    SET time_zone = "+00:00";
     
     
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
     
    --
    -- Base de données :  `ja_tennis`
    --
     
    -- --------------------------------------------------------
     
    --
    -- Structure de la table `tournois`
    --
     
    DROP TABLE IF EXISTS `tournois`;
    CREATE TABLE IF NOT EXISTS `tournois` (
      `tournois_id` int(11) NOT NULL AUTO_INCREMENT,
      `tournois_nom` varchar(255) NOT NULL,
      `tournois_annee` int(11) NOT NULL,
      `tournois_date` varchar(255) NOT NULL,
      PRIMARY KEY (`tournois_id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
     
    --
    -- Déchargement des données de la table `tournois`
    --
     
    INSERT INTO `tournois` (`tournois_id`, `tournois_nom`, `tournois_annee`, `tournois_date`) VALUES
    (1, 'Tournoi hiver', 2019, '09/02/2019 au 24/02/2019'),
    (2, 'Tournoi printemps', 2019, '06/04/2019 au 21/04/2019'),
    (3, 'Tournoi été', 2019, '19/06/2019 au 07/07/2019');
    COMMIT;
     
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Undefined variable: Idclic
    Par kratos59 dans le forum Langage
    Réponses: 7
    Dernier message: 11/05/2006, 16h50
  2. Notice: Undefined variable
    Par oranoutan dans le forum Langage
    Réponses: 19
    Dernier message: 21/12/2005, 22h28
  3. undefined variable
    Par ept35 dans le forum Langage
    Réponses: 3
    Dernier message: 30/11/2005, 15h48
  4. Notice: Undefined variable
    Par kayn dans le forum Langage
    Réponses: 2
    Dernier message: 03/10/2005, 20h44
  5. Réponses: 3
    Dernier message: 22/09/2005, 11h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo