//GET THESE SENT FROM A FORM and possibly parsed/exploded
$start_year = 2011;
$start_month = 3; // (1 = Jan, etc, so 3 = March)
$num_months = 6;
$repeat_day = 3; //(0=sun,1=mon etc, so weds = 3)
$calendar_info = "this, that and the other"; //event details
$x = 0;
$date_clause = "";
while($x < $num_months){
$firstday = date("w", mktime(0, 0, 0, $start_month + $x, 1, $start_year));
if($firstday <= $repeat_day){
$daypart = $repeat_day - $first_day;
}else{
$daypart = 7 + $repeat_day - $first_day;
}
$date_event = date("Y-m-d", mktime(0, 0, 0, $start_month + $x, 1 + $daypart, $start_year));
$date_clauses[] = "('$date_event','$calendar_info')";
$x++;
}
$date_clause = implode(",",$dateclauses);
$r = mysql_query("INSERT INTO events (`date`,`event_details`) VALUES $date_clause");
WARNING: off the top of my head. Not tested at all. Probably over-complicated it. This works onthe premise of finding out the first day of the week of the new month. Then just increment on until you reach the day in question. I* think* this will work even if you go beyond the set year, i.e. you can add 6 months to a start month of November and keep the same year and it should organize itself to change to the next year automatically. Pesky things these dates. I'm sure there must be a simple solution for this - perhaps even a two liner!
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080