2 pièce(s) jointe(s)
Undefined variable tournois
Bonjour, j'aimerais une aide sur un exercice en PHP
Merci d'avance.
Code:
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:
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 */; |