hallo!
ich habe den code für einen kalender, der die termine (start, ende) aus einer datenbank anzeigen soll. leider ist der kalender im moment aber nur so programmiert, dass er den starttag farbig im kalender anzeigt. wie schafft man es, dass sowohl der starttag, der endtag und die dazwischenliegenden tage angezeigt werden? vielen dank schon mal für die hilfe...
[kalender.php]
<style type="text/css">
TD, TH {
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
FONT-SIZE: 8pt;
FONT-WEIGHT: none;
COLOR: black;
BACKGROUND-COLOR: #FBFBFD;
}
.alt {BACKGROUND-COLOR: #FFFFFF;}
.basic {COLOR: white; BACKGROUND-COLOR: #006633;}
.top {COLOR: white; BACKGROUND-COLOR: #669966;}
.white {BACKGROUND-COLOR: #FFFFFF;}
.blank {BACKGROUND-COLOR: white;}
A:link, A:visited, A:active {
COLOR: white;
FONT-WEIGHT: bolder;
TEXT-DECORATION: none;
}
A:hover {COLOR: black;}
</style>
<?
ini_set ("error_reporting","E_ALL & ~E_NOTICE");
// Heutiges Datum, falls noch nichts gesetzt
$tag[] = "00";
$subj[] = "";
if (($year == "") || ($month == "") || ($day == "")) {
$year = date("Y");
$month = date("n");
$day = date("d");
}
mysql_connect("localhost", "", "") or die("could not connect"); // Connect zur DB
mysql_select_db("Seegatterl"); // Datenbank auswählen
$select = "SELECT DATE_FORMAT(termStart,'%d') as SqlTag, termKunde
FROM Buchungen
WHERE
DATE_FORMAT(termStart,'%Y') = $year AND
DATE_FORMAT(termStart,'%m') = $month
ORDER BY termStart
";
$found = mysql_query($select);
while ($row = mysql_fetch_array($found)) {
$tag[] = $row[SqlTag];
$subj[] = $row[termKunde];
}
mysql_free_result($found);
$link_url = "";
$selector = 1;
$highlight = 1;
// Infos für die Kalender-Erstellung
$daysmonth = date("t",mktime(0,0,0,$month,$day,$year));
$firstday = date("w",mktime(0,0,0,$month,1,$year));
$padmonth = date("m",mktime(0,0,0,$month,$day,$year));
$padday = date("d",mktime(0,0,0,$month,$day,$year));
$deutsch = array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
$monat = $deutsch[$padmonth -1];
// Anpassen an $calendar_format
if ($firstday == 0) {
$firstday = 7;
}
$date = "$monat $year";
$dayletter = array(1 => "Mo", 2 => "Di", 3 => "Mi", 4 => "Do", 5 => "Fr", 6 => "Sa", 7 => "So");
$daymod = 0;
?>
<table border="0" cellspacing="0" cellpadding="0" width="150">
<tr>
<td class=basic>
<table width="150" border="0" cellspacing="1" cellpadding="3">
<tr>
<th class=top colspan=7> <font color="#FFFFFF"><b><? echo $date;?></b></font></th>
</tr>
<tr>
<?
for($daynumber = 1; $daynumber < 8; $daynumber++) {
echo "<td><font size='1'>$dayletter[$daynumber]</font></td>";
}
?>
</tr>
<tr>
<?
for ($i = 1; $i < $daysmonth + $firstday + $daymod; $i++) {
$a = $i - $firstday + 1 - $daymod;
$day = $i - $firstday + 1 - $daymod;
if (strlen($a) == 1) {
$a = "0$a";
}
if (($i < $firstday) || ($a == "00")) {
$text = "";
$colour = "white";
$size = 10;
echo "<td class=white> </td>";
$k++;
} else {
$index = 0;
$title = "";
foreach ($tag as $padday) {
if (($padday == $a) && ($highlight)) {
$title = $subj[$index];
if (($i%7) == $daymod) {
$text = "$a";
$colour = "class=top";
break;
} else {
$text = "$a";
$colour = "class=top";
$size = 12;
break;
}
} else {
if (($i%7) == $daymod) {
$text = "$a";
$colour = "class=alt";
$size = 10;
} else {
$text = "$a";
$colour = "";
$size = 10;
}
}
$index++;
}
if (eregi("class=top",$colour)) {
echo "<td $colour><font size='1'><a href='TerminDetail.php?year=$year&month=$month&day=$text' title='$title'>$text</a></font></td>"; // Hier der Link
} else {
echo "<td $colour><font size='1'>$text</font></td>";
}
}
if (($i%7) == 0) {
echo "</TR><TR>\n";
}
}
if (($i%7) != 1) {
echo "</TD>\n";
}
$colspan = 36 - $i;
if ($colspan < 0) {
$colspan = $colspan + 7;
}
for ($i = 0; $i < $colspan; $i++) {
echo "<td class=white> </td>";
}
if ($colspan !=0 ) {
echo "</tr><tr>";
}
// den selector anzeigen
if ($selector) {
if ($month == 1) {
$pyear = $year - 1;
$pmonth = 12;
} else {
$pyear = $year;
$pmonth = $month - 1;
}
if ($month == 12) {
$nyear = $year + 1;
$nmonth = 1;
} else {
$nyear = $year;
$nmonth = $month + 1;
}
$year = date("Y");
$month = date("n");
$day = date("j");
echo "<TD colspan=7 class=top><center><FONT SIZE=-2><A HREF='$link_url?year=$pyear&month=$pmonth&day=1'><<</A> | <A HREF='$link_url?year=$year&month=$month&day=$day'>heute</A> | <A HREF='$link_url?year=$nyear&month=$nmonth&day=1'>>></A></FONT></TD>\n";
}
?>
</tr>
</table>
[termindetail.php]
<?
mysql_connect("localhost", "", "") or die("could not connect"); // Connect zur DB
mysql_select_db("Seegatterl") or die("db falsch"); // Datenbank auswählen
if (!isset($_REQUEST[year]) || !isset($_REQUEST[month]) || !isset($_REQUEST[day])) {
die ("Variablen sind nicht gesetzt");
}
if (strlen($_REQUEST[month]) == 1) {
$_REQUEST[month] = "0".$_REQUEST[month];
}
$varDat = "$_REQUEST[year]"."-"."$_REQUEST[month]"."-"."$_REQUEST[day]";
$select = "SELECT * FROM Buchungen WHERE DATE_FORMAT(termStart,'%Y-%m-%d') = '$varDat' ORDER BY termStart";
$found = mysql_query($select);
while ($row = mysql_fetch_array($found)) {
print "Buchung:<p>Vom<br>$row[termStart]<br>bis<br>$row[termEnd]<br>\n";
print "<br><b>$row[termKunde]</b><br>\n";
print "($row[termDetail])<br>\n";
}
mysql_free_result($found);
?>
[datenbank]
# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Erstellungszeit: 18. Dez 2002 um 13:44
# Server Version: 3.23.51
# PHP Version: 4.1.1
# Datenbank : `Seegatterl`
# --------------------------------------------------------
#
# Tabellenstruktur für Tabelle `buchungen`
#
CREATE TABLE buchungen (
termId int(11) NOT NULL auto_increment,
termStart datetime NOT NULL default '0000-00-00 00:00:00',
termEnd datetime NOT NULL default '0000-00-00 00:00:00',
termKunde varchar(100) NOT NULL default '',
termDetail text,
termLink varchar(100) NOT NULL default '',
termUpdate datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (termId),
KEY termId (termId)
) TYPE=MyISAM;
#
# Daten für Tabelle `buchungen`
#
INSERT INTO buchungen VALUES (3, '2002-12-20 13:13:40', '2002-12-21 13:13:40', 'Martin', 'fdsafdsf', '', '2002-12-18 13:13:40');
ich habe den code für einen kalender, der die termine (start, ende) aus einer datenbank anzeigen soll. leider ist der kalender im moment aber nur so programmiert, dass er den starttag farbig im kalender anzeigt. wie schafft man es, dass sowohl der starttag, der endtag und die dazwischenliegenden tage angezeigt werden? vielen dank schon mal für die hilfe...
[kalender.php]
<style type="text/css">
TD, TH {
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
FONT-SIZE: 8pt;
FONT-WEIGHT: none;
COLOR: black;
BACKGROUND-COLOR: #FBFBFD;
}
.alt {BACKGROUND-COLOR: #FFFFFF;}
.basic {COLOR: white; BACKGROUND-COLOR: #006633;}
.top {COLOR: white; BACKGROUND-COLOR: #669966;}
.white {BACKGROUND-COLOR: #FFFFFF;}
.blank {BACKGROUND-COLOR: white;}
A:link, A:visited, A:active {
COLOR: white;
FONT-WEIGHT: bolder;
TEXT-DECORATION: none;
}
A:hover {COLOR: black;}
</style>
<?
ini_set ("error_reporting","E_ALL & ~E_NOTICE");
// Heutiges Datum, falls noch nichts gesetzt
$tag[] = "00";
$subj[] = "";
if (($year == "") || ($month == "") || ($day == "")) {
$year = date("Y");
$month = date("n");
$day = date("d");
}
mysql_connect("localhost", "", "") or die("could not connect"); // Connect zur DB
mysql_select_db("Seegatterl"); // Datenbank auswählen
$select = "SELECT DATE_FORMAT(termStart,'%d') as SqlTag, termKunde
FROM Buchungen
WHERE
DATE_FORMAT(termStart,'%Y') = $year AND
DATE_FORMAT(termStart,'%m') = $month
ORDER BY termStart
";
$found = mysql_query($select);
while ($row = mysql_fetch_array($found)) {
$tag[] = $row[SqlTag];
$subj[] = $row[termKunde];
}
mysql_free_result($found);
$link_url = "";
$selector = 1;
$highlight = 1;
// Infos für die Kalender-Erstellung
$daysmonth = date("t",mktime(0,0,0,$month,$day,$year));
$firstday = date("w",mktime(0,0,0,$month,1,$year));
$padmonth = date("m",mktime(0,0,0,$month,$day,$year));
$padday = date("d",mktime(0,0,0,$month,$day,$year));
$deutsch = array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
$monat = $deutsch[$padmonth -1];
// Anpassen an $calendar_format
if ($firstday == 0) {
$firstday = 7;
}
$date = "$monat $year";
$dayletter = array(1 => "Mo", 2 => "Di", 3 => "Mi", 4 => "Do", 5 => "Fr", 6 => "Sa", 7 => "So");
$daymod = 0;
?>
<table border="0" cellspacing="0" cellpadding="0" width="150">
<tr>
<td class=basic>
<table width="150" border="0" cellspacing="1" cellpadding="3">
<tr>
<th class=top colspan=7> <font color="#FFFFFF"><b><? echo $date;?></b></font></th>
</tr>
<tr>
<?
for($daynumber = 1; $daynumber < 8; $daynumber++) {
echo "<td><font size='1'>$dayletter[$daynumber]</font></td>";
}
?>
</tr>
<tr>
<?
for ($i = 1; $i < $daysmonth + $firstday + $daymod; $i++) {
$a = $i - $firstday + 1 - $daymod;
$day = $i - $firstday + 1 - $daymod;
if (strlen($a) == 1) {
$a = "0$a";
}
if (($i < $firstday) || ($a == "00")) {
$text = "";
$colour = "white";
$size = 10;
echo "<td class=white> </td>";
$k++;
} else {
$index = 0;
$title = "";
foreach ($tag as $padday) {
if (($padday == $a) && ($highlight)) {
$title = $subj[$index];
if (($i%7) == $daymod) {
$text = "$a";
$colour = "class=top";
break;
} else {
$text = "$a";
$colour = "class=top";
$size = 12;
break;
}
} else {
if (($i%7) == $daymod) {
$text = "$a";
$colour = "class=alt";
$size = 10;
} else {
$text = "$a";
$colour = "";
$size = 10;
}
}
$index++;
}
if (eregi("class=top",$colour)) {
echo "<td $colour><font size='1'><a href='TerminDetail.php?year=$year&month=$month&day=$text' title='$title'>$text</a></font></td>"; // Hier der Link
} else {
echo "<td $colour><font size='1'>$text</font></td>";
}
}
if (($i%7) == 0) {
echo "</TR><TR>\n";
}
}
if (($i%7) != 1) {
echo "</TD>\n";
}
$colspan = 36 - $i;
if ($colspan < 0) {
$colspan = $colspan + 7;
}
for ($i = 0; $i < $colspan; $i++) {
echo "<td class=white> </td>";
}
if ($colspan !=0 ) {
echo "</tr><tr>";
}
// den selector anzeigen
if ($selector) {
if ($month == 1) {
$pyear = $year - 1;
$pmonth = 12;
} else {
$pyear = $year;
$pmonth = $month - 1;
}
if ($month == 12) {
$nyear = $year + 1;
$nmonth = 1;
} else {
$nyear = $year;
$nmonth = $month + 1;
}
$year = date("Y");
$month = date("n");
$day = date("j");
echo "<TD colspan=7 class=top><center><FONT SIZE=-2><A HREF='$link_url?year=$pyear&month=$pmonth&day=1'><<</A> | <A HREF='$link_url?year=$year&month=$month&day=$day'>heute</A> | <A HREF='$link_url?year=$nyear&month=$nmonth&day=1'>>></A></FONT></TD>\n";
}
?>
</tr>
</table>
[termindetail.php]
<?
mysql_connect("localhost", "", "") or die("could not connect"); // Connect zur DB
mysql_select_db("Seegatterl") or die("db falsch"); // Datenbank auswählen
if (!isset($_REQUEST[year]) || !isset($_REQUEST[month]) || !isset($_REQUEST[day])) {
die ("Variablen sind nicht gesetzt");
}
if (strlen($_REQUEST[month]) == 1) {
$_REQUEST[month] = "0".$_REQUEST[month];
}
$varDat = "$_REQUEST[year]"."-"."$_REQUEST[month]"."-"."$_REQUEST[day]";
$select = "SELECT * FROM Buchungen WHERE DATE_FORMAT(termStart,'%Y-%m-%d') = '$varDat' ORDER BY termStart";
$found = mysql_query($select);
while ($row = mysql_fetch_array($found)) {
print "Buchung:<p>Vom<br>$row[termStart]<br>bis<br>$row[termEnd]<br>\n";
print "<br><b>$row[termKunde]</b><br>\n";
print "($row[termDetail])<br>\n";
}
mysql_free_result($found);
?>
[datenbank]
# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Erstellungszeit: 18. Dez 2002 um 13:44
# Server Version: 3.23.51
# PHP Version: 4.1.1
# Datenbank : `Seegatterl`
# --------------------------------------------------------
#
# Tabellenstruktur für Tabelle `buchungen`
#
CREATE TABLE buchungen (
termId int(11) NOT NULL auto_increment,
termStart datetime NOT NULL default '0000-00-00 00:00:00',
termEnd datetime NOT NULL default '0000-00-00 00:00:00',
termKunde varchar(100) NOT NULL default '',
termDetail text,
termLink varchar(100) NOT NULL default '',
termUpdate datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (termId),
KEY termId (termId)
) TYPE=MyISAM;
#
# Daten für Tabelle `buchungen`
#
INSERT INTO buchungen VALUES (3, '2002-12-20 13:13:40', '2002-12-21 13:13:40', 'Martin', 'fdsafdsf', '', '2002-12-18 13:13:40');
Kommentar