I am working on a scheduler. I hit a wall with the weekly option. The option is to have an event be scheduled for however many weeks on specific checked days. I have the code for adding the weeks, but I can't figure out how to get the start date right.

For instance, if the user wants to schedule an event every monday and today is a thursday, how do I count how many days it is from thursday to monday to get the start date if date resets the day number (w) on sunday to 0? The long way of doing this is to do a series of if statements assigning a number to add to today's date. But that's 49 if statements and I'm sure there's a better way, I just can't seem to grasp it.

Thanks in advance

    to give you an idea what I've been trying, the following seems to work logically but times out at the while loop:

    // array of checked boxes in the form

    $checked_days = array($recur_weeks_sun,$recur_weeks_mon,$recur_weeks_tue,
    $recur_weeks_wed,$recur_weeks_thu,$recur_weeks_fri,$recur_weeks_sat);

    foreach ($checked_days as $day) {
    
    	if ($day) {
    
    	$each_days = array(1=>Mon,2=>Tue,3=>Wed,4=>Thu,5=>Fri,6=>Sat,0=>Sun);
    	$get_day_num = array_search ("$day", $each_days);
    
    	$bg_day = date("w", mktime(0,0,0,$start_month,$start_day,$start_year));
    	$start_date_loop = $datebox3;
    
    while ($bg_day != $get_day_num) {
    
    $bg_day = date("w", mktime(0,0,0,$start_month,$start_day+1,$start_year));
    $start_date_loop = date("m/d/Y", mktime(0,0,0,$start_month,$start_day+1,$start_year));
    
    } 
    
    echo "$start_date_loop";	
    
    	}

    }

    In my head the logic is: loop through the checkbox array. If the day is checked, create an array of the days and their day numbers according to date. Do a search of the new array with the day (result $get_day_num). Get the beginning day number (bg_day). If bg_day isn't equal to $get_day_num, increment the daynumber and the start_date until the correct day number is reached. That correct day number should be the correct start date for the event.

    Does that make any sense?

    Thanks

      Write a Reply...