/ Published in: PHP
This is using list items to create the calendar so it is very flexible with CSS. Right now it's just displaying dummy data, but you can easily integrate a mysql call into the loop.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Calendar</title> <style type='text/css'> #calendar {width:900px; overflow:auto; margin:0 auto;} li {width:14%; height:120px; display:block; position:relative; float:left; border:#000 1px solid; border-width:1px 0 0 1px; overflow:hidden;} .last {border-right-width:1px;} .lastweek {border-bottom-width:1px;} .today {background:#ccc;} .today .date {background:#333; color:#fff; font-weight:bold;} .date {display:block; width:20px; height:20px; position:relative; top:0; left:0; text-align:center; border:#000 1px solid; border-width:0 1px 1px 0;} li p {padding:0 4px; margin:0;} </style> </head> <body> <div id='calendar'> <?php function calendar($setdate) { $m = $boom[0]; $y = $boom[1]; $count = 1; $weeks = 1; if($startday==0){ $weekcount++; } echo "<div id='controls'><a href='?caldate=$prev' id='prevmonth' class='left'>$prev - prev</a> | $setdate | <a href='?caldate=$next' id='nextmonth' class='right'>next - $next</a></div>"; for($i=0; $i<$startday; $i++){ echo "<li class='blank'></li>"; $count++; } foreach ($days as $value) { echo "<li class='"; if ($count == 7){ echo "last "; $count = 1; } else if ($count == 1){ $weeks++; $count++; } else { $count++; } if ($weeks == $weekcount){ echo "lastweek"; } echo " today"; } echo "'><div class='date'>$value</div><p>Title 1<br />Title 2</p></li>"; } for($i=0; $i<$lastli; $i++){ if ($count == 7){ echo "<li class='blank last lastweek'></li>"; $count = 1; } else { echo "<li class='blank lastweek'></li>"; $count++; } } } } else { $date = $_REQUEST['caldate']; } calendar($date); ?> </div><!-- calendar --> </body> </html>
URL: http://smple.com/snipplr/calendar.php