Jeg er gået igang med en kalender. I admin sektionen af hjemmesiden skal man kunne tilføje events til en bestemt dato. Jeg har så lavet 2 filer.
Den først er hvor jeg tilføjer en dato og et event i databasen:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("scdb");
mysql_query("INSERT INTO kalender(dato,event) VALUES ('$aar-$maaned-$dag' , '$event')" ) or die(mysql_error());
print ('<form action="test.php?insert" method="post" style="margin: 0px;">');
print ('<select name="dag">');
for ($dag = 1; $dag <= 31; $dag++) {
printf('<option value="%02d">%02d</option>', $dag, $dag);
}
print ('</select>');
print ('<select name="maaned">');
for ($maaned = 1; $maaned <= 12; $maaned++) {
printf('<option value="%02d">%02d</option>', $maaned, $maaned);
}
print ('</select>');
print ('<select name="aar">');
for ($aar = 2005; $aar <= 2015; $aar++) {
printf('<option value="%d">%d</option>', $aar, $aar);
}
print ('<input name="event" type="text" value="Skriv eventet her" size="40" maxlength="30">');
print ('</select>');
print ('<br><br>');
print ('<input name="submit" type="submit" value="Gem">');
?>
</body>
</html>
Min anden fil udtrækker så de indtastede datoer og events:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("scdb");
$result = mysql_query("SELECT *, DATE_FORMAT(dato, '%d/%c/%Y') as datoen FROM kalender");
while ($data = mysql_fetch_array($result))
{
?>
<table width="561" border="1" bordercolor="#000000" cellspacing="1" cellpadding="0">
<tr><td width="50%">Dato:
<? print $data['datoen']; ?>
</td><td width="50%">Event:
<? print $data['event']; ?>
</td>
</tr>
</table>
<? } ?>
<body>
</body>
</html>
Det jeg så gerne vil er at integrere dette med en kalender jeg har fundet:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Calendar Test</title>
</head>
<body>
<?
// User callback function to show a day in the calendar
function mycal_show_month_day($year, $month, $day)
{
return($day);
}
/*
* bool mycal_show_month(string day_callback, int year, int month)
* Show a calendar in month view
* This function shows a calendar, it takes the following arguments:
* - string day_callback:
* The name of a user function which gets called for each day of the month.
* Can be used for example to show a day bold or plain depending whether events are stored for this day.
* The callback function must return the day as integer and take three arguments: int year, int month and int day.
* - int year:
* Year to show.
* - int month
* Month to show.
*/
function mycal_show_month($day_callback, $year = 0, $month = 0)
{
// set up default value for month (current month) if none was specified
if($month == 0)
{
$month = date( "m");
}
// setup default value for year (current year) if none was specified
if($year == 0)
{
$year = date( "Y");
}
$prev_month = date( "m", mktime(0, 0, 0, $month - 1, 1, $year));
$next_month = date( "m", mktime(0, 0, 0, $month + 1, 1, $year));
$prev_year = date( "Y", mktime(0, 0, 0, $month - 1, 1, $year));
$next_year = date( "Y", mktime(0, 0, 0, $month + 1, 1, $year));
?>
<style TYPE="text/css">
TD.Some
{
font-family :Tahoma, Verdana, Arial;
font-size :12px;
color :#000000;
font-weight :normal;
}
A
{
font-family :Tahoma, Verdana, Arial;
font-size :12px;
color :#000000;
font-weight :normal;
text-decoration: none;
}
</style>
<table align="CENTER" border="1" cellspacing="0" cellpadding="2" bgcolor="WHITE" bordercolor="Gray">
<tr>
<td>
<table width="140" border="0" cellpadding="1" cellspacing="0"
bgcolor="#FFFFFF">
<tr height="18" bgcolor="Silver">
<td width="20" height="18" align="RIGHT" valign="MIDDLE"> <a href=" <?
print(basename($PHP_SELF));
print( "?month=$prev_month");
print( "&year=$prev_year");
?>" class="noevent"><</a> </td>
<td width="120" colspan="5" align="CENTER" valign="MIDDLE" class="SOME">
<?
print(date( "F", mktime(0, 0, 0, $month, 1, $year)). " $year");
?> </td>
<td width="20" height="18" align="RIGHT" valign="MIDDLE"> <a href=" <?
print(basename($PHP_SELF));
print( "?month=$next_month");
print( "&year=$next_year");
?>" class="noevent">></a> </td>
</tr>
<tr>
<td align="RIGHT" class="SOME" width="20" height="15">S</td>
<td align="RIGHT" class="SOME" width="20" height="15">M</td>
<td align="RIGHT" class="SOME" width="20" height="15">T</td>
<td align="RIGHT" class="SOME" width="20" height="15">W</td>
<td align="RIGHT" class="SOME" width="20" height="15">T</td>
<td align="RIGHT" class="SOME" width="20" height="15">F</td>
<td align="RIGHT" class="SOME" width="20" height="15">S</td>
</tr>
<tr>
<td height="1" align="MIDDLE" colspan="7">
<hr size="1" noshade>
</td>
</tr>
<?
$day = 1 - date( "w", mktime(0, 0, 0, $month, 1, $year));
$days_in_month = date( "t", mktime(0, 0, 0, $month, 1, $year));
// Loop through all days in the month
while($day <= $days_in_month)
{
print( "<tr>");
// Print a row containing seven days
for ($j=1; $j<=7; $j++)
{
?>
<td align='right' width=20 height=15 valign='bottom' class='some'>
<?
print(($day <= $days_in_month && $day > 0) ? $day_callback($year, $month, $day): " ");
?>
</td>
<?
$day++;
}
print( "</tr>");
}
?>
</table>
</td>
</tr>
</table>
<?
return(true);
}
mycal_show_month( "mycal_show_month_day", $year, $month);
?>
</body>
</html>
(den kan ses på www.livegames.dk/kalender2.php
Jeg har tænkt noget med at lave nogle if/else sætninger når den laver datoerne, men jeg ved ikke helt hvordan jeg skal bære mig ad. Nogle der vil hjælpe?