1156834800/2006-08-29
1157439600/2006-09-05
1158044400/2006-09-12
1158649200/2006-09-19
1159254000/2006-09-26
1159858800/2006-10-03
1160463600/2006-10-10
1161068400/2006-10-17
1161673200/2006-10-24
1162278000/2006-10-30
1162882800/2006-11-06
1163487600/2006-11-13
1164092400/2006-11-20
1164697200/2006-11-27
1165302000/2006-12-04
You can see for the month of October or 10 the second last date is 24 and last day is 30 instead of it being 31 which is 24+7 which it is doing prefectly in all other cases. Any help on this will be appreciated. Thanks in advance
The code is as below
Code: Select all
$dayschedulearray[6] = "Mon/Wed";
$dayschedulearray[7] = "Tue/Thu";
$dayschedulearray[8] = "Mon/Wed/Fri";
$dayschedulearray[1] = "Mon";
$dayschedulearray[2] = "Tue";
$dayschedulearray[3] = "Wed";
$dayschedulearray[4] = "Thu";
$dayschedulearray[5] = "Fri";
$dayschedule[6] = "Monday";
$dayschedule[7] = "Tuesday";
$dayschedule[8] = "Monday";
$dayschedule[1] = "Monday";
$dayschedule[2] = "Tuesday";
$dayschedule[3] = "Wednesday";
$dayschedule[4] = "Thursday";
$dayschedule[5] = "Friday";
if(!$conn=mysql_connect('192.168.2.5','webaccess','dcpass'))
die("Could not connect to mysql.\n".mysql_error());
mysql_select_db("den");
$query = mysql_query("select c.day, c.datein, c.dateout, c.timein, c.timeout, co.deptcno, c.studio from courserequest c , course co where c.course = co.cid order by c.id DESC limit 1") or die (mysql_error());
while ($result = mysql_fetch_array($query))
{
$sem_start = $result['datein'];
$sem_end = $result['dateout'];
$day = $result['day'];
$course_day = $dayschedule[$day];
list($sem_year, $sem_month, $sem_day) = explode("-", $result['datein']);
//$sem_start_date = ;
$sem_start_day = date("l", mktime(0, 0, 0, $sem_month, $sem_day, $sem_year));
//echo $sem_start_day.",".$course_day;
$sem_start_date = strtotime($sem_start);
switch ($sem_start_day)
{
case "Monday":
if($course_day == 'Monday')
$newdate = $sem_start_date;
if($course_day == 'Tuesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 1);
if($course_day == 'Wednesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 2);
if($course_day == 'Thursday')
$newdate = $sem_start_date + (60 * 60 * 24 * 3);
if($course_day == 'Friday')
$newdate = $sem_start_date + (60 * 60 * 24 * 4);
//echo "One";
break;
case "Tuesday":
if($course_day == 'Monday')
$newdate = $sem_start_date + (60 * 60 * 24 * 6);
if($course_day == 'Tuesday')
$newdate = $sem_start_date ;
if($course_day == 'Wednesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 1);
if($course_day == 'Thursday')
$newdate = $sem_start_date + (60 * 60 * 24 * 2);
if($course_day == 'Friday')
$newdate = $sem_start_date + (60 * 60 * 24 * 3);
//echo "Two";
break;
case "Wednesday":
if($course_day == 'Monday')
$newdate = $sem_start_date + (60 * 60 * 24 * 5);
if($course_day == 'Tuesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 6);
if($course_day == 'Wednesday')
$newdate = $sem_start_date ;
if($course_day == 'Thursday')
$newdate = $sem_start_date + (60 * 60 * 24 * 1);
if($course_day == 'Friday')
$newdate = $sem_start_date + (60 * 60 * 24 * 2);
//echo "Two";
break;
case "Thursday":
if($course_day == 'Monday')
$newdate = $sem_start_date + (60 * 60 * 24 * 4);
if($course_day == 'Tuesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 5);
if($course_day == 'Wednesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 6);
if($course_day == 'Thursday')
$newdate = $sem_start_date ;
if($course_day == 'Friday')
$newdate = $sem_start_date + (60 * 60 * 24 * 1);
//echo "Two";
break;
case "Friday":
if($course_day == 'Monday')
$newdate = $sem_start_date + (60 * 60 * 24 * 3);
if($course_day == 'Tuesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 4);
if($course_day == 'Wednesday')
$newdate = $sem_start_date + (60 * 60 * 24 * 5);
if($course_day == 'Thursday')
$newdate = $sem_start_date + (60 * 60 * 24 * 6);
if($course_day == 'Friday')
$newdate = $sem_start_date ;
//echo "Two";
break;
default:
echo "Day mismatch";
//break;
}
//echo date('y-m-d', $newdate);
$sem_end_date = strtotime($sem_end);
if(!$conn2=mysql_connect('localhost','root','partytime'))
die("Could not connect to local mysql.\n".mysql_error());
mysql_select_db("vcalendar");
$timein = date('H:i:s' , strtotime($result['timein']));
$timeout = date('H:i:s' , strtotime($result['timeout']));
// adds values to events table
// $add2base = mysql_query("insert into events (event_id, user_id, category_id, event_title, event_date, event_time, event_time_end, event_is_public ) values ('', '2', '" . $result['studio'] . "', '" . $result['deptcno'] . "', '" . date('y-m-d', $newdate) . "', '" . $timein . "', '" . $timeout . "', '1')") or die("MySQL error - insert error:<br>" . mysql_error());
//
// $lastinserted = mysql_insert_id();
//echo $sem_end_date."<br>";
$newdate2 = $newdate + (60 * 60 * 24 * 7);
echo $newdate2."/".date('Y-m-d', $newdate2)."<br>";
while( $sem_end_date > $newdate2)
{
// adds values to events table
// $add2base = mysql_query("insert into events (event_parent_id, user_id, category_id, event_title, event_date, event_time, event_time_end, event_is_public ) values ('".$lastinserted."', '2', '" . $result['studio'] . "', '" . $result['deptcno'] . "', '" . date('y-m-d', $newdate2) . "', '" . $timein . "', '" . $timeout . "', '1')") or die("MySQL error - insert error:<br>" . mysql_error());
$newdate2 = $newdate2 + (60 * 60 * 24 * 7);
echo $newdate2."/".date('Y-m-d', $newdate2)."<br>";
}
//echo "insert into events (event_parent_id, user_id, category_id, event_title, event_date, event_time, event_time_end, event_is_public ) values ('', '2', '" . $result['studio'] . "', '" . $result['deptcno'] . "', '" . date('y-m-d', $newdate) . "', '" . $timein . "', '" . $timeout . "', '1')";
}