Kaldender
Ik heb een script waar je in een html form een datum invult en mijn php script dan informatie geeft over die datum. Nu wil ik een kalender op mijn website zetten waar je op een bepaalde datum kan klikken en dat mijn php script dan van die datum info laat zien zoiets: $datum = aangeklikte datum.
Alvast bedankt voor de hulp.
Kilian
En wat is de vraag?
Hoe ik zo'n kalender maak die op het moment dat je op een bepaalde datum klikt $datum de aangeklikte datum maakt.
link:
pagina.php?datum=12-2-10
$datum = $_GET['datum']
Ik weet effe niet waar de kalenders te vinden, maar google effe op javascript calendar, dan vind je er wel 1.
Succes.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/* ====================================================================
* Copyright (c) 2005 Astonish Inc.
* www.blazonry.com/scripting/datemenu_php.php
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
$m = (!$m) ? date("m",mktime()) : "$m";
$y = (!$y) ? date("Y",mktime()) : "$y";
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$eventdate = $_POST['eventdate'];
$event = $_POST['event'];
echo "<br />";
echo "<h2>PHP Event Calendar</h2>";
echo "This is a demo. We are not saving the event to the calendar, but you could.<br /><br />";
echo "We are demo-ing building the calendar, and interacting with it.<br /><br />";
echo "<b>Event:</b> $event<br />";
echo "<b>Date:</b> $eventdate<br />";
exit();
}
?>
<html>
<head>
<title>PHP Event Calendar</title>
</head>
<body bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC">
<h2>PHP Event Calendar</h2>
<blockquote>
<table>
<tr>
<td valign="top"><?php mk_drawCalendar($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>
<form name="f" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add New Event</b></font></td></tr>
<tr><td><b>Event Date: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">mm/dd/yyyy</font></td></tr>
<tr><td><b>Event:</b></td><td><input type="text" name="event" size="35" maxlength="128"></td></tr>
<tr><td colspan="2" align="center" bgcolor="#CCCCCC"><input type="submit" value="Add Event"></td></tr>
</table></td></tr></table></form>
</td>
</tr></table>
</blockquote>
</body>
</html>
<?php
//*********************************************************
// DRAW CALENDAR
//*********************************************************
/*
Draws out a calendar (in html) of the month/year
passed to it date passed in format mm-dd-yyyy
*/
function mk_drawCalendar($m,$y)
{
if ((!$m) || (!$y))
{
$m = date("m",mktime());
$y = date("Y",mktime());
}
/*== get what weekday the first is on ==*/
$tmpd = getdate(mktime(0,0,0,$m,1,$y));
$month = $tmpd["month"];
$firstwday= $tmpd["wday"];
$lastday = mk_getLastDayofMonth($m,$y);
?>
<table cellpadding="2" cellspacing="0" border="1">
<tr><td colspan="7" bgcolor="#CCCCDD">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
<th><font size=2><?="$month $y"?></font></th>
<th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
</tr></table>
</td></tr>
<tr><th width=22 class="tcell">Su</th><th width=22 class="tcell">M</th>
<th width=22 class="tcell">T </th><th width=22 class="tcell">W</th>
<th width=22 class="tcell">Th</th><th width=22 class="tcell">F</th>
<th width=22 class="tcell">Sa</th></tr>
<?php $d = 1;
$wday = $firstwday;
$firstweek = true;
/*== loop through all the days of the month ==*/
while ( $d <= $lastday)
{
/*== set up blank days for first week ==*/
if ($firstweek) {
echo "<tr>";
for ($i=1; $i<=$firstwday; $i++)
{ echo "<td><font size=2> </font></td>"; }
$firstweek = false;
}
/*== Sunday start week with <tr> ==*/
if ($wday==0) { echo "<tr>"; }
/*== check for event ==*/
echo "<td class='tcell'>";
echo "<a href=\"#\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
echo "</td>\n";
/*== Saturday end week with </tr> ==*/
if ($wday==6) { echo "</tr>\n"; }
$wday++;
$wday = $wday % 7;
$d++;
}
?>
</tr></table>
Click on a date to select it and to populate the event date field on the left
<br />
<?php
/*== end drawCalendar function ==*/
}
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
for ($tday=28; $tday <= 31; $tday++)
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon)
{ break; }
}
$tday--;
return $tday;
}
?>
/* ====================================================================
* Copyright (c) 2005 Astonish Inc.
* www.blazonry.com/scripting/datemenu_php.php
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
$m = (!$m) ? date("m",mktime()) : "$m";
$y = (!$y) ? date("Y",mktime()) : "$y";
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$eventdate = $_POST['eventdate'];
$event = $_POST['event'];
echo "<br />";
echo "<h2>PHP Event Calendar</h2>";
echo "This is a demo. We are not saving the event to the calendar, but you could.<br /><br />";
echo "We are demo-ing building the calendar, and interacting with it.<br /><br />";
echo "<b>Event:</b> $event<br />";
echo "<b>Date:</b> $eventdate<br />";
exit();
}
?>
<html>
<head>
<title>PHP Event Calendar</title>
</head>
<body bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC">
<h2>PHP Event Calendar</h2>
<blockquote>
<table>
<tr>
<td valign="top"><?php mk_drawCalendar($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>
<form name="f" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table cellpadding="4" cellspacing="1" border="0 "bgcolor="#FFFFFF">
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add New Event</b></font></td></tr>
<tr><td><b>Event Date: </b></td><td><input type="text" name="eventdate" value="" size="12"> <font size="2">mm/dd/yyyy</font></td></tr>
<tr><td><b>Event:</b></td><td><input type="text" name="event" size="35" maxlength="128"></td></tr>
<tr><td colspan="2" align="center" bgcolor="#CCCCCC"><input type="submit" value="Add Event"></td></tr>
</table></td></tr></table></form>
</td>
</tr></table>
</blockquote>
</body>
</html>
<?php
//*********************************************************
// DRAW CALENDAR
//*********************************************************
/*
Draws out a calendar (in html) of the month/year
passed to it date passed in format mm-dd-yyyy
*/
function mk_drawCalendar($m,$y)
{
if ((!$m) || (!$y))
{
$m = date("m",mktime());
$y = date("Y",mktime());
}
/*== get what weekday the first is on ==*/
$tmpd = getdate(mktime(0,0,0,$m,1,$y));
$month = $tmpd["month"];
$firstwday= $tmpd["wday"];
$lastday = mk_getLastDayofMonth($m,$y);
?>
<table cellpadding="2" cellspacing="0" border="1">
<tr><td colspan="7" bgcolor="#CCCCDD">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
<th><font size=2><?="$month $y"?></font></th>
<th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
</tr></table>
</td></tr>
<tr><th width=22 class="tcell">Su</th><th width=22 class="tcell">M</th>
<th width=22 class="tcell">T </th><th width=22 class="tcell">W</th>
<th width=22 class="tcell">Th</th><th width=22 class="tcell">F</th>
<th width=22 class="tcell">Sa</th></tr>
<?php $d = 1;
$wday = $firstwday;
$firstweek = true;
/*== loop through all the days of the month ==*/
while ( $d <= $lastday)
{
/*== set up blank days for first week ==*/
if ($firstweek) {
echo "<tr>";
for ($i=1; $i<=$firstwday; $i++)
{ echo "<td><font size=2> </font></td>"; }
$firstweek = false;
}
/*== Sunday start week with <tr> ==*/
if ($wday==0) { echo "<tr>"; }
/*== check for event ==*/
echo "<td class='tcell'>";
echo "<a href=\"#\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
echo "</td>\n";
/*== Saturday end week with </tr> ==*/
if ($wday==6) { echo "</tr>\n"; }
$wday++;
$wday = $wday % 7;
$d++;
}
?>
</tr></table>
Click on a date to select it and to populate the event date field on the left
<br />
<?php
/*== end drawCalendar function ==*/
}
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
for ($tday=28; $tday <= 31; $tday++)
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon)
{ break; }
}
$tday--;
return $tday;
}
?>
Zou iemand mij kunnen helpen door ervoor te zorgen dat $datum de aangeklikte datum wordt? Het liefst in het formaat: yyyy-mm-dd
Alvast bedankt
Gewijzigd op 01/01/1970 01:00:00 door Kilian Janssen
Dan krijg je een GET variabele ($_GET['datum'];) met de datum.
Deze kan je dan weer gebruiken in je database.
Zet in je database een datum en een evenement en je kan het daarna weer uitlezen.
edit: Het stukje wat eronder staat werkt dan niet meer he.
Gewijzigd op 01/01/1970 01:00:00 door Michael -
Turmin, dit is nog steeds voor die KNMI website, mensen die op de kalender iets aan klikken moeten het weer van die dag zien, hoe doe ik dit?
SELECT * FROM .... WHERE date = mysq_real_escape_string($_GET['datum'])
Mysql_real_escape string om sql_injection te voor komen. Of gebruik checkdate() die ook in het knmi script is gebruikt.