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
| <?php
function dateToFrench($date, $format)
{
$english_days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
$french_days = array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche');
$english_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$french_months = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
return str_replace($english_months, $french_months, str_replace($english_days, $french_days, date($format, strtotime($date) ) ) );
}
$db = new PDO('mysql:host=localhost;dbname=projet','root',''); // connexion bdd
$data = array();
$date = date("Y-m-d"); // date du jour
$recup_cours = $db->query("SELECT * FROM edt WHERE date >= '".$date."'"); // requete SQL pour récupérer les données du jour et futur
?>
<table>
<?php
$jour = array(null, "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi");
while($all = $recup_cours->fetch())
{
$data[] = $all;
list($annee, $mois, $jour) = explode('-', $all['date']); // Permet de découper la date en mois, jour et annee
$timestamp = mktime(0, 0, 0, $mois, $jour, $annee);
$cours = $all['cours'];
$heure = $all['heure'];
$day = date('D', $timestamp); // formate la date SQL ex:("2019-05-08") en jour ex:(Mon, Tue, Wed...)
$yourdatetime = $heure;
$timestamp = strtotime($yourdatetime);
$horaire = date('H', $timestamp); // formate l'heure SQL ex:("16:00:00:000000") en int ex:(16, 17, 18...)
$day = dateToFrench($day,'l'); // Permet de "convertir les jours ("Mon, Tue, Wed...") en jours ("Lundi, Mardi, Mercredi....")
$rdv[$day][$horaire] = $cours;
echo "<tr><th scope='row'>Heure</th>";
for($x = 1; $x < 6; $x++)
echo "<th scope='row'>".$jour[$x]."</th>";
echo "</tr>";
for($j = 8; $j < 18; $j += 1)
{
echo "<tr>";
for($i = 0; $i < 5; $i++)
{
if($i == 0)
{
$heure = str_replace("0.5", ":30", $j);
echo "<th class=\"time\">".$heure."</th>";
}
echo "<td>";
if(isset($rdv[$jour[$i+1]][$heure]))
{
echo $rdv[$jour[$i+1]][$heure];
}
echo "</td>";
}
echo "</tr>";
}
}
if (count($data)<=0){
echo '<tr><td>Aucune données trouvées</td></tr>';
}
?>
</table>
<?php
?> |
Partager