Moderator |
|
CREATE TABLE birthday (
month int(2) NOT NULL default '0',
day int(2) NOT NULL default '0',
year int(4) NOT NULL default '0',
name varchar(30) NOT NULL default ''
) TYPE=MyISAM;
CREATE TABLE birthday ( month int(2) NOT NULL default '0', day int(2) NOT NULL default '0', year int(4) NOT NULL default '0', name varchar(30) NOT NULL default '' ) TYPE=MyISAM;
Dit is een OUD script, dus ff aanpassen aan eigen gebruik (en ff conntecten naar je DB uiteraard ;)).
Ik wéét dat er eea beter kan, maar dit script is illustratief genoeg.
<?php
$user = "...";
$pass = "...";
$dbase = "...";
$host = "...";
if(!mysql_connect($host, $user, $pass)) {
echo "Cannot connect to database";
exit;
} else {
mysql_select_db($dbase);
}
?>
<HTML>
<HEAD>
<TITLE>birthday calendar</TITLE>
<STYLE>
<!--
.top {BACKGROUND-COLOR: #999999;}
BODY {FONT-FAMILY: Arial;
FONT-SIZE: 8pt;
COLOR: #000000;}
TD {FONT-FAMILY: Arial;
FONT-SIZE: 8pt;
COLOR: #000000;}
A:LINK {FONT-SIZE: 8pt;
FONT-WEIGHT: bold;
TEXT-DECORATION: none;
COLOR: #0000ff;}
A:VISITED {TEXT-DECORATION: none;
FONT-WEIGHT: bold;
COLOR: #0000ff;}
A:ACTIVE {TEXT-DECORATION: underline;
FONT-WEIGHT: bold;
COLOR: #ff0000;}
A:HOVER {TEXT-DECORATION: underline;
FONT-WEIGHT: bold;
COLOR: #ff0000;}
//-->
</STYLE>
</HEAD>
<BODY>
<U>birthday calendar</U><BR><BR>
<TABLE WIDTH="900" BORDER="1" CELLSPACING="0" CELLPADDING="1">
<TR CLASS="top">
<TD>jan<BR></TD>
<TD>feb<BR></TD>
<TD>mar<BR></TD>
<TD>apr<BR></TD>
<TD>may<BR></TD>
<TD>jun<BR></TD>
<TD>jul<BR></TD>
<TD>aug<BR></TD>
<TD>sep<BR></TD>
<TD>oct<BR></TD>
<TD>nov<BR></TD>
<TD>dec<BR></TD>
</TR>
<?
echo "<TR>";
for($c = 1; $c <=12; $c++) {
$month = mysql_query("select day, name from birthday where month=$c order by day asc");
echo " <TD WIDTH=\"75\" VALIGN=\"top\">";
if(!mysql_num_rows($month)) {
echo " <BR>\n";
} else {
while($bd = mysql_fetch_array($month)) {
echo " <A HREF=\"calendar.php?d=".$bd['day']."&m=".$c."\">";
echo ($bd['day'] < 10 ? "0" : "").$bd['day']." ".array_pop(array_reverse(explode(" ",$bd['name'])))."</A><BR>";
}
}
echo " </TD>";
}
echo "</TR>";
?>
</TABLE>
<BR>
<?
// Bepaal datum voor het berekenen van leeftijden
list($a_day, $a_month, $a_year) = split(' ',date("j n Y"));
if(!empty($_GET['d']) && !empty($_GET['m'])) {
$res = mysql_query("select * from birthday where month='$m' and day='$d' order by year asc");
echo ($d < 10 ? "0" : "").$d." ";
switch($m) {
case 1: echo "January" ; break;
case 2: echo "February" ; break;
case 3: echo "March" ; break;
case 4: echo "April" ; break;
case 5: echo "May" ; break;
case 6: echo "June" ; break;
case 7: echo "July" ; break;
case 8: echo "August" ; break;
case 9: echo "September"; break;
case 10: echo "October" ; break;
case 11: echo "November" ; break;
case 12: echo "December" ; break;
}
echo "<BR>";
echo "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"3\">";
while($names = mysql_fetch_array($res)) {
echo "<TR>";
echo "<TD>";
echo $names['year']." - <B>".$names['name']."</B>";
echo "</TD>";
// berekenen van leeftijd
if(($a_month < $m) || ($a_day < $d && $a_month == $m)) {
$age = $a_year - $names['year'] - 1;
}
if(($a_month > $m) || ($a_day >= $d && $a_month == $m)) {
$age = $a_year - $names['year'];
}
echo "<TD>";
echo " <FONT COLOR=\"#0000ff\">".$age."</FONT><BR>";
echo "</TD>";
echo "</TR>";
}
echo "</TABLE>";
} else {
echo "click on a date to see more info.<BR>";
}
?>
</BODY>
</HTML>
<?php $user = "..."; $pass = "..."; $dbase = "..."; $host = "..."; echo "Cannot connect to database"; } else { } ?> <HTML> <HEAD> <TITLE>birthday calendar</TITLE> <STYLE> <!-- .top {BACKGROUND-COLOR: #999999;} BODY {FONT-FAMILY: Arial; FONT-SIZE: 8pt; COLOR: #000000;} TD {FONT-FAMILY: Arial; FONT-SIZE: 8pt; COLOR: #000000;} A:LINK {FONT-SIZE: 8pt; FONT-WEIGHT: bold; TEXT-DECORATION: none; COLOR: #0000ff;} A:VISITED {TEXT-DECORATION: none; FONT-WEIGHT: bold; COLOR: #0000ff;} A:ACTIVE {TEXT-DECORATION: underline; FONT-WEIGHT: bold; COLOR: #ff0000;} A:HOVER {TEXT-DECORATION: underline; FONT-WEIGHT: bold; COLOR: #ff0000;} //--> </STYLE> </HEAD> <BODY> <U>birthday calendar</U><BR><BR> <TABLE WIDTH="900" BORDER="1" CELLSPACING="0" CELLPADDING="1"> <TR CLASS="top"> <TD>jan<BR></TD> <TD>feb<BR></TD> <TD>mar<BR></TD> <TD>apr<BR></TD> <TD>may<BR></TD> <TD>jun<BR></TD> <TD>jul<BR></TD> <TD>aug<BR></TD> <TD>sep<BR></TD> <TD>oct<BR></TD> <TD>nov<BR></TD> <TD>dec<BR></TD> </TR> <? for($c = 1; $c <=12; $c++) { $month = mysql_query("select day, name from birthday where month=$c order by day asc"); echo " <TD WIDTH=\"75\" VALIGN=\"top\">"; } else { echo " <A HREF=\"calendar.php?d=".$bd['day']."&m=".$c."\">"; } } } ?> </TABLE> <BR> <? // Bepaal datum voor het berekenen van leeftijden $res = mysql_query("select * from birthday where month='$m' and day='$d' order by year asc"); echo ($d < 10 ? "0" : "").$d." "; switch($m) { case 1: echo "January" ; break; case 2: echo "February" ; break; case 3: echo "March" ; break; case 4: echo "April" ; break; case 5: echo "May" ; break; case 6: echo "June" ; break; case 7: echo "July" ; break; case 8: echo "August" ; break; case 9: echo "September"; break; case 10: echo "October" ; break; case 11: echo "November" ; break; case 12: echo "December" ; break; } echo "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"3\">"; echo $names['year']." - <B>".$names['name']."</B>"; // berekenen van leeftijd if(($a_month < $m) || ($a_day < $d && $a_month == $m)) { $age = $a_year - $names['year'] - 1; } if(($a_month > $m) || ($a_day >= $d && $a_month == $m)) { $age = $a_year - $names['year']; } echo " <FONT COLOR=\"#0000ff\">".$age."</FONT><BR>"; } } else { echo "click on a date to see more info.<BR>"; } ?> </BODY> </HTML>
|