PHP/Mysql Kalender
Ik ben bezig met een kalender script en zit met een probleem.
Ik wil dat hij tijdens het wegschrijven van de dagen een check uitvoert of er voor deze dag een event is gepland. Zo ja? In eerste instansie gewoon echo 'E'.$dayNum;
Maar ik heb geen idee hoe ik het hier in krijg zonder nog vaker een query uit te voeren. Heeft iemand een suggestie ?
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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Tunder's Calendar</title>
<link rel="stylesheet" href="css/master.css" type="text/css" media="screen" charset="utf-8" />
<script src="js/jquery-1.3.min.js" type="text/javascript"> </script>
<script src="js/coda.js" type="text/javascript"> </script>
</head>
<body>
<?php
$date = time();
$today = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
$firstDay = mktime(0, 0, 0, $month, 1, $year);
$title = date('F', $firstDay);
$dayOfWeek = date('D', $firstDay);
switch($dayOfWeek){
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;
}
$daysInMonth = cal_days_in_month(0, $month, $year);
echo '<h1>'.$title.' '.$year.'</h1>';
?>
<table cellspacing="0">
<thead>
<tr>
<th>Ma</th><th>Di</th><th>Wo</th>
<th>Do</th><th>Vri</th><th>Za</th>
<th>Zo</th>
</tr>
</thead>
<tbody>
<?php
$dayCount = $blank+1;
echo '<tr>';
echo '<td class="padding" colspan="'.$blank.'"></td>';
//mysql_connect('localhost','****','****');
//mysql_select_db('****');
//$sql = 'SELECT * FROM calendar WHERE date > "'.$year.'-'.$month.'-00" AND date < "'.$year.'-'.$month.'-32"';
//$res = mysql_query($sql);
$dayNum = 1;
while($dayNum <= $daysInMonth){
if($dayNum == $today){
echo '<td class="today">'.$dayNum.'</td>';
}else{
echo '<td>'.$dayNum.'</td>';
}
$dayNum++;
$dayCount++;
if($dayCount > 7){
echo '</tr><tr>';
$dayCount = 1;
}
}
while($dayCount > 1 && $dayCount <= 7){
$dayCount++;
}
echo '<td class="padding" colspan="'.$dayCount.'"></td>';
?>
</tbody>
<tfoot>
<th>Ma</th><th>Di</th><th>Wo</th>
<th>Do</th><th>Vri</th><th>Za</th>
<th>Zo</th>
</tfoot>
</table>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Tunder's Calendar</title>
<link rel="stylesheet" href="css/master.css" type="text/css" media="screen" charset="utf-8" />
<script src="js/jquery-1.3.min.js" type="text/javascript"> </script>
<script src="js/coda.js" type="text/javascript"> </script>
</head>
<body>
<?php
$date = time();
$today = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
$firstDay = mktime(0, 0, 0, $month, 1, $year);
$title = date('F', $firstDay);
$dayOfWeek = date('D', $firstDay);
switch($dayOfWeek){
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;
}
$daysInMonth = cal_days_in_month(0, $month, $year);
echo '<h1>'.$title.' '.$year.'</h1>';
?>
<table cellspacing="0">
<thead>
<tr>
<th>Ma</th><th>Di</th><th>Wo</th>
<th>Do</th><th>Vri</th><th>Za</th>
<th>Zo</th>
</tr>
</thead>
<tbody>
<?php
$dayCount = $blank+1;
echo '<tr>';
echo '<td class="padding" colspan="'.$blank.'"></td>';
//mysql_connect('localhost','****','****');
//mysql_select_db('****');
//$sql = 'SELECT * FROM calendar WHERE date > "'.$year.'-'.$month.'-00" AND date < "'.$year.'-'.$month.'-32"';
//$res = mysql_query($sql);
$dayNum = 1;
while($dayNum <= $daysInMonth){
if($dayNum == $today){
echo '<td class="today">'.$dayNum.'</td>';
}else{
echo '<td>'.$dayNum.'</td>';
}
$dayNum++;
$dayCount++;
if($dayCount > 7){
echo '</tr><tr>';
$dayCount = 1;
}
}
while($dayCount > 1 && $dayCount <= 7){
$dayCount++;
}
echo '<td class="padding" colspan="'.$dayCount.'"></td>';
?>
</tbody>
<tfoot>
<th>Ma</th><th>Di</th><th>Wo</th>
<th>Do</th><th>Vri</th><th>Za</th>
<th>Zo</th>
</tfoot>
</table>
</body>
</html>
Toevoeging op 28/09/2010 20:00:48:
De link naar het online voorbeeld is http://tunder-design.nl/calendar/ voor mensen die het wouden zien ^^
Gewijzigd op 28/09/2010 20:38:42 door Jos Verra
En als dat dus de query is die je wil gaan gebruiken, gebruik van liever de date/time functies van je SQL engine zelf.
Dat was mijn plan ook daarom vraag ik om verdere suggesties ^^
Oke, in die tabel "calendar" staan alle evenementen?
Gewijzigd op 28/09/2010 21:16:24 door Jos Verra