j'ai trouver partiellement la solution mais j'ai un message d'erreur qui apparait lorsque je lance la page web .
avant de charger le fichier csv dans la bdd j'ai les messages suivants :
-Warning: Undefined variable $days in C:\code\projet_meteo\index.php on line 62
-Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in C:\code\projet_meteo\index.php on line 62
-TypeError: array_merge(): Argument #1 must be of type array, null given in C:\code\projet_meteo\index.php on line 62
voici mon code php merci de votre retour.
<?php
//connexion erveur
$mysqli = new mysqli('localhost', 'root', '', 'bdd_meteo');
if ($mysqli->connect_errno) {
echo 'Echec de la connection' . $mysqli->connect_error;
exit();
}
//traitement des données csv pour les insérer dans la bdd
if (isset($_GET["charger"])) {
if(($handle = fopen("meteo.csv", "r")) !== FALSE){
while (($data = fgetcsv($handle, 10000, ";")) !== FALSE)
{
$date = $data[0];
$ville = $data[1];
$periode = $data[2];
$resum = $data[3];
$id_resume = $data[4];
$temp_min = $data[5];
$temp_max = $data[6];
$commentaire = $data[7];
$mysqli->query('INSERT INTO infos_meteo (jour, ville, periode, resum, id_resume, temp_min, temp_max, commentaire)
VALUES ("'. $date .'" , "'. $ville .'" ,"'. $periode .'" , "'. $resum .'" , "'. $id_resume .'" , "'. $temp_min .'" , "'. $temp_max .'" , "'. $commentaire .'")');
}
fclose($handle);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="index.php" method="get">
<input type="submit" name="charger" value="charger" >
</form>
<?php
//requete php
$result_day = $mysqli->query('SELECT infos_meteo_id, jour FROM infos_meteo');
//boucle pour récuperer les donnée
while ($row =$result_day->fetch_array()){
$days[$row['infos_meteo_id']] = $row['jour'];}
//fusion des différents tableaux
$merge = array_merge($days);
$dat_unique = array_unique($merge);
?>
<?php
foreach($dat_unique as $jj) {?>
<form action="index.php" method="get">
<ul>
<li><a href="index.php?momment=<?php echo $jj; ?>"><?php echo $jj; ?></a></li>
</ul>
</form>
<?php }; ?>
<p>bienvenu sur le site des prévisions de la méteo à deux jours
les prévision sont données à deux jours à date du jour
</p>
<table>
<thead>
<tr>
<th>Jour</th>
<th>Ville</th>
<th>Période</th>
<th>Résumé</th>
<th>Id résumé</th>
<th>Température min</th>
<th>Température max</th>
<th>Commentaire</th>
</tr>
</thead>
<?php
if(isset($_GET['momment'])){
$j = $_GET['momment'];
$result = $mysqli->query('SELECT infos_meteo_id, jour, ville, periode, resum, id_resume, temp_min, temp_max, commentaire FROM infos_meteo WHERE jour > "'.$j.'"');
while ($row =$result->fetch_array()){ ?>
<tbody>
<tr>
<td><?php echo $row['jour']; ?></td>
<td><?php echo $row['ville']; ?></td>
<td><?php echo $row['periode']; ?></td>
<td><?php echo $row['resum']; ?></td>
<td><?php echo $row['id_resume']; ?></td>
<td><?php echo $row['temp_min']; ?></td>
<td><?php echo $row['temp_max']; ?></td>
<td><?php echo $row['commentaire']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</body>
</html>