marker dato i kalender hvis der er en event i db
Hvordan markerer jeg en dato i min kalender, hvis der er en tilhørende event?Det er lykkedes at få markeret det sidst tilføjede felt i db.
<?php
//This gets today's date
$date =time () ;
//This puts the day, month, and year in seperate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
if (isset($_GET['day'])) {
$day = $_GET['day'];
}
if (isset($_GET['month'])) {
$month = $_GET['month'];
}
if (isset($_GET['year'])) {
$year = $_GET['year'];
}
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;
//This gets us the month name
$title = date('F', $first_day) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day) ;
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week){
case "Mon": $blank = 0; break;
case "Tue": $blank = 1; break;
case "Wed": $blank = 2; break;
case "Thu": $blank = 3; break;
case "Fri": $blank = 4; break;
case "Sat": $blank = 5; break;
case "Sun": $blank = 6; break;
}
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;
//Here we start building the table heads
echo "<table width=196px>";
#echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr id='tr_1'><td width=28>Man</td><td width=28>Tir</td><td width=28>Ons</td><td width=28>Tor</td><td width=28>Fre</td><td width=28>Lør</td><td width=28>Søn</td></tr>";
//This counts the days in the week, up to 7
$day_count = 1;
echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 )
{
echo "<td id='td_1'>-</td>";
$blank = $blank-1;
$day_count++;
}
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month )
{
$hent_dato = mysqli_query($db, "select * from kalender");
while($hent_dato1 = mysqli_fetch_array($hent_dato)){
$event = $hent_dato1['dato'];
};
if($event == $_GET['year']."-".$_GET['month']."-".$day_num){
echo "<td id='td_11'>";
}elseif($event != $_GET['year']."-".$_GET['month']."-".$day_num){
echo "<td id='td_1'>";
};
if(isset($_GET['month']) && isset($_GET['year'])){
echo "<a href='?page=kalender&day=".$day_num."&month=".$_GET['month']."&year=".$_GET['year']."'>".$day_num."</a>";
};
if(!isset($_GET['month']) && !isset($_GET['year'])){
echo "<a href='?page=kalender&day=".$day_num."&month=".$month."&year=".$year."'>".$day_num."</a>";
};
echo "</td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 )
{
echo "<td id='td_1'>-</td>";
$day_count++;
}
echo "</tr></table>";
$year2 = $_GET['year'];
$year1 = $_GET['year'];
if(!empty($_GET['month'])){
$naeste = $_GET['month']+1;
if($_GET['month']+1 > 12){
$_GET['year'] = $year+1;
};
};
$naeste = $month+1;
$forrige = $_GET['month']-1;
if($_GET['month']+1 > 12){
$naeste = 1;
};
if(!empty($_GET['year'])){
$year1 = $_GET['year'];
};
if(empty($_GET['year'])){
$year1 = $year;
};
if(isset($_GET['month'])){
if($_GET['month']-1 < 1){
$forrige = 12;
$year2 = $_GET['year']-1;
};
};
if(!isset($_GET['month'])){
$year2 = $year;
$forrige = $month-1;
};
echo "<span class='pil'><a href='?day=".$day."&month=".$forrige."&year=".$year2."'><<</a></span> ";
echo "<span class='måned'>".$title."</span>";
echo " <span class='pil'><a href='?day=".$day."&month=".$naeste."&year=".$year1."'>>></a></span>";
?>
