Hej.
Jeg er i gang med at finde en kalender, og jeg har dette.
Men hvordan kan jeg koble den sammen med MySQl databsen? En der vil hjælpe ?
Koden PT:
<?php
setlocale( LC_TIME, 'da_DK' );
$today = time();
if ( !empty( $_GET['m'] ) && !empty( $_GET['y'] ) && is_numeric( $_GET['m'] ) && is_numeric( $_GET['y'] ) )
{
$today = mktime( 0, 0, 0, $_GET['m'], 1, $_GET['y'] );
}
$mname = ucfirst( strftime( '%B', $today ) );
$thism = date( 'm', $today );
$thisy = date( 'Y', $today );
$startd = mktime( 0, 0, 0, $thism, 1, $thisy );
$endd = mktime( 23, 59, 59, $thism + 1, 0, $thisy );
$nodays = date( 'd', $endd );
$startwd = strftime( '%u', $startd );
$endwd = strftime( '%u', $endd );
$startw = strftime( '%V', $startd );
$endw = strftime( '%V', $endd );
$startpad = ( $startwd == 1 ? 0 : $startwd - 1 );
$realstart = mktime( 0, 0, 0, $thism, -$startpad + 1, $thisy );
$startpadreal = date( 'd', $realstart );
$endpad = ( $endwd == 7 ? 0 : 7 - $endwd );
$realend = strtotime( '+' . $endpad . ' days', $endd );
$lastm = date( 'm', strtotime( '-1 month', $today ) );
$lastmy = date( 'Y', strtotime( '-1 month', $today ) );
$nextm = date( 'm', strtotime( '+1 month', $today ) );
$nextmy = date( 'Y', strtotime( '+1 month', $today ) );
$days = array();
$w = $startw;
$n = 0;
if ( $startpad > 0 )
{
for ( $i = $startpadreal; $i < $startpadreal + $startpad; $i++ )
{
$days[$w][] = $i;
$n++;
}
}
for ( $i = 1; $i <= $nodays; $i++ )
{
$n %= 7;
if ( $n == 0 )
{
$w = strftime( '%V', mktime( 0, 0, 0, $thism, $i, $thisy ) );
}
$days[$w][] = $i;
$n++;
}
if ( $endpad > 0 )
{
for ( $i = 1; $i <= $endpad; $i++ )
{
$days[$endw][] = $i;
}
}
?>
<html>
<head>
<title>Kalender for <?= $mname ?></title>
<style>
body {
background-color: white;
font-family: tahoma, verdana, arial, helveica;
font-size: 11pt;
}
.mnav {
background-color: #eeeeee;
font-size: 14pt;
text-align: center;
}
.hdr {
text-align: center;
font-size: 16pt;
}
th { background-color: #eeeeee; }
.wkn {
background-color: #eeeeee;
text-align: center;
}
.notnow {
background-color: #eeeeee;
color: #888888;
}
.satd { background-color: #ddffdd; }
.sund { background-color: #ffdddd; }
.date { font-size: 9pt; }
</style>
</head>
<body>
<h1>Kalender for <?= $mname ?></h1>
<table id="cal" width="760px" border="1" cellspacing="0" cellpadding="0">
<tr>
<td class='mnav'><a title="Forrige måned" href="<?= $_SERVER['PHP_SELF'] . '?y=' . $lastmy . '&m=' . $lastm ?>">«</a></td>
<td class="hdr" colspan="6"><?= $mname . ', ' . $thisy ?></td>
<td class='mnav'><a title="Næste måned" href="<?= $_SERVER['PHP_SELF'] . '?y=' . $nextmy . '&m=' . $nextm ?>">»</a></td>
</tr>
<tr>
<th style="width: 50px">Uge</th>
<th>Man</th>
<th>Tir</th>
<th>Ons</th>
<th>Tor</th>
<th>Fre</th>
<th style="width: 75px">Lør</th>
<th style="width: 75px">Søn</th>
</tr>
<?php
foreach ( $days as $wk => $dayar )
{
echo "<tr><td class=\\"wkn\\">$wk</td>";
for ( $d = 0; $d < 7; $d++ )
{
$c = '';
if ( $d == 5 )
{
$c .= ' satd';
}
elseif ( $d == 6 )
{
$c .= ' sund';
}
$tm = $thism;
$ty = $thisy;
if ( ( $wk == $startw && $dayar[$d] > 10 ) ||
( $wk == $endw && $dayar[$d] < 10 ) )
{
$c .= ' notnow';
if ( $dayar[$d] > 10 )
{
$tm = $lastm;
}
else
{
$tm = $nextm;
}
if ( $thism == 1 && $dayar[$d] > 10 )
{
$ty = $thisy - 1;
}
else if ( $thism == 12 && $dayar[$d] < 10 )
{
$ty = $thisy + 1;
}
}
$tstamp = mktime( 0, 0, 0, $tm, $dayar[$d], $ty );
if ( $c != '' )
{
$c = ' class="' . $c . '"';
}
$td = sprintf( '%02d', $dayar[$d] );
$typ = ( $d > 4 ? 'dwecnt' : 'dcnt' );
$cb = '';
printf( "<td$c><div class='%s'><div class='date'>%d%s</div>", $typ, $td, $cb );
echo "Her er plads til du kan skrive noget";
echo '</div></td>';
}
echo "</tr>\\n";
}
?>
</table>
</body>
</html>