In my database, there are some days with data and some without; I have one column with data, and another column with the date and time submitted. So I want to create this calendar. So it will show all the days in the month, and then the days with data will be a hyperlink. When I click the link, it will show all the data submitted on that day. I would probably use a loop within the first loop. One for month, and then one for displaying each and every day. However, being that each month of the year has different amount of days and also leap year is a problem, I don't know how to write the conditions. Any help or guidance is appreciated.
$start = '2009-01-01';
$current = strtotime($start);
while(date('n',$current)==date('n',strtotime($start))) {
// do your stuff here, $current includes the current date.
// the loop will run through the complete month
$current = strtotime(date('Y-m-d',$current) . '+1 day');
}
You'll need to first find out what day of the week the month starts, so you know how many empty boxes to spit out. Then figure out how many days in that month. Then loop through your days, wrapping to the next line after Saturday. Then fill in the rest of the last row with empty boxes.
There's some quite simple (and commented) code that does this here:
http://gitorious.org/wfpl/wfpl/blobs/master/calendar.php
You can use that code without the rest of the framework it's designed for, if you simply rewrite calender_day()
(which is called for each cell on the calendar, with it's first parameter telling you what sort of day it is (not in month, has events, eventless) and rewrite calendar_week()
which is called at the end of each row.
Or you could just look through for how to do relevant stuff, like find out how far through the week the month starts and such.