This is the script
<?php
//$choix_Id= 521
//Partie SQL
//$sql = "SELECT noperiode FROM Reservations WHERE ref_Choix = //$choix_Id;
//$nopériode= $période+10;
// Fuseau horaire de Toronto (le plus près surpporté selon manuel php)
date_default_timezone_set('America/Toronto');
// Passer d'un mois à l'autre
if (isset($_GET['ym'])) {
$mois = $_GET['ym'];
} else {
// Le mois consulté
$mois = date('Y-m');
}
// "strtotime Transforme un texte anglais en timestamp" - manuel php
$timestamp = strtotime($mois . '-01');
if ($timestamp === false) {
$mois = date('Y-m');
$timestamp = strtotime($mois . '-01');
}
// Aujourdhui
$aujourdhui = date('Y-m-j', time());
// Titre calendrier/mois
$titre_mois = date('Y / m', $timestamp);
// lien du mois suivant ou précédent
$précedant = date('Y-m', strtotime('-1 month', $timestamp));
$suivant = date('Y-m', strtotime('+1 month', $timestamp));
// Nombre de jours dans le mois
$nb_jours = date('t', $timestamp);
// 0:Dim 1:Lun 2:Mar ...
$str = date('w', $timestamp);
// Création du calendrier
$semaines = array();
$semaine = '';
// Création de cellules vides
$semaine .= str_repeat('<td></td>', $str);
$nosemcal= 3;
$noperiodecal=array(2,3,5);
$len_noper = count($noperiodecal)-1;
echo $len_noper;
for ( $jour = 1; $jour <= $nb_jours; $jour++, $str++) {
//for($i=0; $i<=$len_noper;$i++){
$date = $mois . '-' . $jour;
$semainecal = date("W",strtotime($date))-13;
$periodecal = date("w",strtotime($date));
//for ($i=0; $i<=$len_noper;$i++){
if ($nosemcal==$semainecal and $noperiodecal[2]==$periodecal) {
$semaine .= '<td class="reserve">' . $jour;
}else {
$semaine .= '<td class="dispo">' . $jour;
}
// Fin de la semaine ou du mois
if ($str % 7 == 6 || $jour == $nb_jours) {
if ($jour == $nb_jours) {
// nouvelle cellule vide
$semaine .= str_repeat('<td></td>', 6 - ($str % 7));
}
$semaines[] = '<tr>' . $semaine . '</tr>';
// Début d'une nouvelle semaine
$semaine = '';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Calendrier Disponibilités</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonmoisous">
<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
<style>
.fond {
font-family: 'Noto Sans', sans-serif;
margin-top: 80px;
}
h3 {
margin-bottom: 30px;
}
th {
height: 30px;
text-align: center;
}
td {
height: 100px;
}
.dispo {
background: green;
}
.reserve {
background: red;
}
</style>
</head>
<body>
<div class="fond">
<h3><a href="?mois=<?php echo $précedant; ?>"><</a> <?php echo $titre_mois; ?> <a href="?mois=<?php echo $suivant; ?>">></a></h3>
<table class="table table-bordered">
<tr>
<th>D</th>
<th>L</th>
<th>M</th>
<th>M</th>
<th>J</th>
<th>V</th>
<th>S</th>
</tr>
<?php
foreach ($semaines as $semaine) {
echo $semaine;
}
?>
</table>
</div>
</body>
</html>
This is the result enter image description here
What i want is all the days in the array $noperiodecal to be in red not just one and without repeating the days of the calendar or the calendar itself. So the 19th, 20th and 22th of April 2022 but not manually like I did for the 19th. I've tried to move the for($i) loop but it changes the whole calendar each times.