Track Meet Results Calendar
/* draws a calendar */
function draw_calendar($month,$year,$events = array()){
/* draw table */
$calendar = '';
/* table headings */
$headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$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 = '';
/* 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;
}
?>
echo '
';?>
'.implode(' | ',$headings).' |
'; $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.= '';
}
}
else {
$calendar.= str_repeat(' ',2); } $calendar.= ' | ';
if($running_day == 6):
$calendar.= '
'; endfor; endif; /* final row */ $calendar.= ' |
'.date('F',mktime(0,0,0,$month,1,$year)).' '.$year.'
'; echo ''.$controls.'
';
echo '';
echo draw_calendar($month,$year,$events);
echo '';?>