Track Meet Results Calendar

'; /* table headings */ $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $calendar.= ''.implode('',$headings).''; /* days and weeks vars now ... */ $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); /* row for week one */ $calendar.= ''; /* print "blank" days until the first of the current week */ for($x = 0; $x < $running_day; $x++): $calendar.= ' '; $days_in_this_week++; endfor; /* keep going with days.... */ for($list_day = 1; $list_day <= $days_in_month; $list_day++): $calendar.= '
'; /* add in the day number */ $calendar.= '
'.$list_day.'
'; $event_day = $year.'-'.$month.'-'.$list_day; $NewListDay = sprintf("%02s", $list_day); $NewEventDay=$month.'/'.$NewListDay.'/'.$year; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '
'.$event['Name'].'
'.$event['City'].' '.$event['State'].'

'; } } else { $calendar.= str_repeat('

 

',2); } $calendar.= '
'; if($running_day == 6): $calendar.= ''; if(($day_counter+1) != $days_in_month): $calendar.= ''; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; /* finish the rest of the days in the week */ if($days_in_this_week < 8): for($x = 1; $x <= (8 - $days_in_this_week); $x++): $calendar.= ' '; endfor; endif; /* final row */ $calendar.= ''; /* end the table */ $calendar.= ''; /** DEBUG **/ $calendar = str_replace('',''."\n",$calendar); $calendar = str_replace('',''."\n",$calendar); /* all done, return result */ return $calendar; } function random_number() { srand(time()); return (rand() % 7); } /* date settings */ $month = (int) ($_GET['month'] ? $_GET['month'] : date('m')); $year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); /* select month control */ $select_month_control = ''; /* select year control */ $year_range = 7; $select_year_control = ''; /* "next month" control */ $next_month_link = 'Next Month >>'; /* "previous month" control */ $previous_month_link = '<< Previous Month'; /* bringing the controls together */ $controls = '
'.$select_month_control.$select_year_control.'        '.$previous_month_link.'     '.$next_month_link.'
'; /* get all events for the given month */ $now=time(); $tUPDATE="UPDATE MR_meet SET EZDate=DATE_FORMAT(FROM_UNIXTIME(`Date`),'%Y-%m') WHERE EZDate=''"; $con->query($tUPDATE); $month = sprintf("%02s", $month); $events = array(); $query="SELECT MR_meet.id, MR_meet.Name,trackresults.meetid, MR_meet.EZDate, MR_meet.City, MR_meet.State, Date AS event_date FROM MR_meet LEFT JOIN trackresults ON MR_meet.id=trackresults.meetid WHERE MR_meet.EZDate LIKE '$year-$month' AND trackresults.meetid != 'NULL' GROUP BY MR_meet.id"; //$query = "SELECT title, DATE_FORMAT(event_date,'%Y-%m-%D') AS event_date FROM events WHERE event_date LIKE '$year-$month%'"; $result = $con->query($query); while($row = $result->fetch_assoc()) { $EDa=$row['event_date']; $event_date=date("Y-m-j",$EDa); echo "TEST".$event_date; $events[$event_date][] = $row; } ?> '.date('F',mktime(0,0,0,$month,1,$year)).' '.$year.''; echo '
'.$controls.'
'; echo '
'; echo draw_calendar($month,$year,$events); echo '

';?>