Piece of Cake!
home about calendar dear diary recipes links letters to the editor

Calendar

0){ $offset_correction = array_slice($num_days_last_array, -$offset, $offset); $new_count = array_merge($offset_correction, $num_days_array); $offset_count = count($offset_correction); } // The else statement is to prevent building the $offset array. else { $offset_count = 0; $new_count = $num_days_array; } // count how many days we have with the two // previous arrays merged together $current_num = count($new_count); // Since we will have 5 HTML table rows (TR) // with 7 table data entries (TD) // we need to fill in 35 TDs // so, we will have to figure out // how many days to appened to the end // of the final array to make it 35 days. if($current_num > 35){ $num_weeks = 6; $outset = (42 - $current_num); } elseif($current_num < 35){ $num_weeks = 5; $outset = (35 - $current_num); } if($current_num == 35){ $num_weeks = 5; $outset = 0; } // Outset Correction for($i = 1; $i <= $outset; $i++){ $new_count[] = $i; } // Now let's "chunk" the $all_days array // into weeks. Each week has 7 days // so we will array_chunk it into 7 days. $weeks = array_chunk($new_count, 7); // Build Previous and Next Links $previous_link = "<< Prev"; $next_link = "Next >>"; // Build the heading portion of the calendar table echo "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n". /* "\n". */ "\n". "\n". "\n"; // Connect to wotan mysqli_connect("localhost","kcarr","bananas"); $link=mysqli_connect("localhost","kcarr","bananas"); mysqli_select_db($link,'kcarr'); $error=mysqli_error($link); if($error){ print "mySQL error: $error
"; } // Set time zone and get today's date date_default_timezone_set('EST'); $today_date=date(Y).date(m).date(d); $query="SELECT title, date, time, description, url, id FROM events"; $result=mysqli_query($link, $query); // Now we break each key of the array // into a week and create a new table row for each // week with the days of that week in the table data $i = 0; while ($columns=mysqli_fetch_array($result)){ $date=$columns['date']; $days_with_events[$columns['date']]=1; $titles[$date]=$columns['title']; $times[$date]=$columns['time']; $descriptions[$date]=$columns['description']; $urls[$date]=$columns['url']; $ids[$date]=$columns['id']; } //print_r($days_with_events); foreach($weeks AS $week){ echo "\n"; foreach($week as $d){ if($d<10){ $d="0$d"; } $full_date=$year.'-'.$month.'-'.$d; if($days_with_events[$full_date]){ echo "\n"; } else { echo "\n"; } } echo "\n"; } /* if($i < $offset_count){ $day_link = "$d"; echo "\n"; } if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){ $day_link = "$d"; if($date == mktime(0,0,0,$month,$d,$year)){ echo "\n"; } else { echo "\n"; } } elseif(($outset > 0)) { if(($i >= ($num_weeks * 7) - $outset)){ $day_link = "$d"; echo "\n"; } $i++; */ // Close out your table and that's it! echo ''; echo '
$previous_link$month_name $year$next_link
SMTWTFS
$d
$titles[$full_date]
$d
$day_link$d$day_link$day_link
'; ?>

Valid XHTML 1.0!