Calendrier divisé en semaines
sage
-
miramaze Messages postés 1429 Date d'inscription Statut Contributeur Dernière intervention -
miramaze Messages postés 1429 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour, je voudrais faire un séparer ce calendrier en semaines où chaque semaine aurait des jours allant de 0 à 6 mais je ne sais pas par où commencer, j'ai essayé d'utiliser le $str mais là je bloque
<?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['mois'])) {
$mois = $_GET['mois'];
} 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);
$jour1_sem = array(
"-1" => "03-27",
"0" => "04-3",
"1" => "04-10",
"2" => "04-17",
"3" => "04-24",
"4" => "05-1",
"5" => "05-8",
"6" => "05-15",
"7" => "05-22",
"8" => "05-29",
"9" => "06-5",
"10" => "06-12",
"11" => "06-19",
"12" => "06-26",
"13" => "07-3",
"14" => "07-10",
"15" => "07-17",
"16" => "07-24"
);
for ( $jour = 1; $jour <= $nb_jours; $jour++) {
$str = date('w', $timestamp);
$date_dim= date('m-j', strtotime($aujourdhui . " -" . $str. " days"));
$periode = $str + 10;
$noSemaine = $jour1_sem["$date_dim"];
//Requete
$date = $mois . '-' . $jour;
if ($aujourdhui > $date) {
$semaine .= '<td class="avant">' . $jour;
} else {
$semaine .= '<td class="case">' . $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;
}
.case {
background: green;
}
.avant {
background: blue;
}
</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>
<?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['mois'])) {
$mois = $_GET['mois'];
} 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);
for ( $jour = 1; $jour <= $nb_jours; $jour++, $str++) {
$date_dim= date('m-j', strtotime($aujourdhui . " -" . $str. " days"));
$date = $mois . '-' . $jour;
if ($aujourdhui > $date) {
$semaine .= '<td class="avant">' . $jour;
} else {
$semaine .= '<td class="case">' . $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;
}
.case {
background: green;
}
.avant {
background: blue;
}
</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>
<?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['mois'])) {
$mois = $_GET['mois'];
} 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);
$jour1_sem = array(
"-1" => "03-27",
"0" => "04-3",
"1" => "04-10",
"2" => "04-17",
"3" => "04-24",
"4" => "05-1",
"5" => "05-8",
"6" => "05-15",
"7" => "05-22",
"8" => "05-29",
"9" => "06-5",
"10" => "06-12",
"11" => "06-19",
"12" => "06-26",
"13" => "07-3",
"14" => "07-10",
"15" => "07-17",
"16" => "07-24"
);
for ( $jour = 1; $jour <= $nb_jours; $jour++) {
$str = date('w', $timestamp);
$date_dim= date('m-j', strtotime($aujourdhui . " -" . $str. " days"));
$periode = $str + 10;
$noSemaine = $jour1_sem["$date_dim"];
//Requete
$date = $mois . '-' . $jour;
if ($aujourdhui > $date) {
$semaine .= '<td class="avant">' . $jour;
} else {
$semaine .= '<td class="case">' . $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;
}
.case {
background: green;
}
.avant {
background: blue;
}
</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>
<?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['mois'])) {
$mois = $_GET['mois'];
} 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);
for ( $jour = 1; $jour <= $nb_jours; $jour++, $str++) {
$date_dim= date('m-j', strtotime($aujourdhui . " -" . $str. " days"));
$date = $mois . '-' . $jour;
if ($aujourdhui > $date) {
$semaine .= '<td class="avant">' . $jour;
} else {
$semaine .= '<td class="case">' . $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;
}
.case {
background: green;
}
.avant {
background: blue;
}
</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>
Configuration: Windows / Chrome 100.0.4896.127
A voir également:
- Calendrier divisé en semaines
- Mon calendrier - Télécharger - Santé & Bien-être
- Logiciel gratuit conversion calendrier républicain - Télécharger - Études & Formations
- Calendrier partagé google - Guide
- Synchroniser calendrier outlook et gmail - Guide
- 1 milliard divisé par 1 million - Accueil - Technologies
1 réponse
Hello,
tu devrais déjà formatter ton code pour que ce soit lisible => https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code. On dirait qu'une partie du code est en doublon, je ne comprends pas.
Il faudrait comprendre le but final de tout ça mais tu as pensé à l'option de faire ça entièrement en javascript ?
tu devrais déjà formatter ton code pour que ce soit lisible => https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code. On dirait qu'une partie du code est en doublon, je ne comprends pas.
Il faudrait comprendre le but final de tout ça mais tu as pensé à l'option de faire ça entièrement en javascript ?