Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How would I get this script to work with different time intervals?

I'm building a calendar and I'm trying to implement the same kind of features you would find on your iphone as far as being able to schedule repeating events.

I was able to get this to work for an event that happens everyday from the starting date to the ending date:

if($_POST['frequency']=="every day")
	{
	$the_start = strtotime($_POST['start_month'].' '.$_POST['start_day'].' '.$_POST['start_year']);
	$the_end = strtotime($_POST['end_month'].' '.$_POST['end_day'].' '.$_POST['end_year']);
	$num_days=$the_end-$the_start;
	$datediff= floor($num_days/(60*60*24));
	//here's your insert code
	$new_event_start=$event_start;
		for ($i=0; $i<=$datediff; $i++)
		{
		$insert = "insert into calendar (event_name, event_start, event_end, event_category, event_desc)
		values ('$event_name', '$new_event_start', '$event_end', '$event_category', '$event_desc')";
		$insertexe = mysqli_query($cxn, $insert);
			if(!$insertexe) {
			$error = mysqli_errno($cxn).': '.mysqli_error($cxn);
			die($error);
			} ;
		$new_event_start=date('Y-m-d H:i:s', strtotime($new_event_start) + 86400);
	  }
		//echo "$datediff dates have been added";
	}

Open in new window


But I don't know how I would do this for every week, and every two weeks.

Thoughts?
SOLUTION
Avatar of mcnute
mcnute
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial