Afficher des données dans un Calendrier PHP

Petit nouveau ! | 1 Messages

20 août 2020, 19:38

Bonjour à tous,
J'ai besoin d'un coup de main au sujet de l'affichage d'un événement dans un calendrier en PHP, ledit événement devrait provenir d'une Base de données ...
Voici mon Code du Calendrier :

<?php
include('connexion.php');
session_start();
include('compteur.php');

if(!isset($_SESSION['user_login']))
{
header('Location: ../index.html');
exit();
}

// Set your timezone!!
date_default_timezone_set('Europe/Paris');
/* date_default_timezone_set('Asia/Tokyo'); */

// Get prev & next month
if(isset($_GET['ym'])){
$ym = $_GET['ym'];
} else {
// This month
$ym = date('Y-m');
}

// Check format
$timestamp = strtotime($ym,"-01");
if ($timestamp === false) {
$timestamp = time();
}

// Today
$today = date('Y-m-d', time());

// For H3 title
$html_title = date('Y / m', $timestamp);

// Create prev & next month link.....mktime(hour,minute,second,month,day,year)
$prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp)));
$next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp)));

// Number of days in the month
$day_count = date('t', $timestamp);

// 0:Sun 1:Mon 2:Tue.....
$str = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp)));

// Create Calendar!!
$weeks = array();
$week = '';

// Add empty cell
$week .= str_repeat('<td></td>', $str);

for ( $day = 1; $day <= $day_count; $day++, $str++) {

$date = $ym.'-'.$day;

if ($today == $date) {
$week .= '<td class="today">'.$day;
} else {
$week .= '<td>'.$day;
}
$week .= '</td>';

// End of the week OR End of the month
if ($str % 7 == 6 || $day == $day_count) {

if ($day == $day_count) {
// Add empty cell
$week .= str_repeat('<td></td>', 6 - ($str % 7));
}

$weeks[] = '<tr>'.$week.'</tr>';

// Prepare for new week
$week = '';
}
}
?>

Ensuite, il y a le code HTML qui affiche ce calendrier :
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>PHP Calendar</title>
<!-- Latest compiled and minified CSS Bootstrap 3.3.6 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstr ... ap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?famil ... splay=swap" rel="stylesheet">
<style>
.container {
font-family: 'Noto Sans', sans-serif;
margin-top: 80px;
margin-bottom: 80px;
/*margin-bottom: 20px;*/
}
th {
height: 30px;
text-align: center;
/*text-align: justify;*/
font-weight: 700;
border: 1px solid #09F;
}
td {
height: 80px;
/*height: 100px;*/
width: 200px;
border: 1px solid #09F;
/*border: 1px solid #0186ba;*/
/*border: 1px solid #E20613;*/
vertical-align: top;
padding: 5px;
}
.today {
background: orange;
/*background: lightblue;*/
}
th:nth-of-type(7),td:nth-of-type(7) {
color: blue;
}
th:nth-of-type(1),td:nth-of-type(1) {
color: red;
}
</style>
</head>

<body>
<div class="container">
<h3><a href="?ym=<?php echo $prev; ?>"><</a> <?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">></a></h3>
<br>
<table class="table.table-bordered">
<tr>
<th>Dimanche</th>
<th>Lundi</th>
<th>Mardi</th>
<th>Mercredi</th>
<th>Jeudi</th>
<th>Vendredi</th>
<th>Samedi</th>
</tr>
<?php
foreach ($weeks as $week) {
echo $week;
}
?>
</table>
</div>
</body>
</html>

Enfin, j'ai essayé d'insérer le script PHP ci-dessous, pour afficher mes données provenant d'une des tables, mais ce données s'affichent en dehors du calendrier, en plus elles sont présentes partout lorsqu'on parcourt le calendrier par mois.
Voici le script :
<?php
$sql = $bdd->prepare('SELECT
commande.id_commande,
code_cmd,
date_cmd,
sigle_client,
nom_client,
code_formation,
lib_module,
nb_stg,
devis_servtec,
etat_cmd,
comment_cmd

FROM
commande,
client,
formation,
moduleformation
WHERE

client.id_client=commande.id_client AND
formation.id_formation=commande.id_formation AND
moduleformation.id_moduleformation=commande.id_moduleformation

ORDER BY id_commande DESC');

$sql->execute();

while($dcalen = $sql->fetch())
{
?>
<a style="font-weight: bold;" href="view_commande_day.php?cmday=<?php echo html_entity_decode($dcalen['id_commande'].' - '.$dcalen['code_cmd']); ?>"><?php echo html_entity_decode($dcalen['id_commande'].' - '.$dcalen['code_cmd']); ?></a>
<?php
}

Comment faire ?