Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi Everyone,
I am using the following code to generate 3 schedules in three tables one is a schedule with 7 day intervals and two are daily schedules.
But when I run the script the two daily schedules seem to have the wrong (out of sync) dates at the start of each schedule. The dates look as if they may be dates from the preceding loop.
I am presuming that I need to reset something after the completion of each loop but I am not sure what.
Many thanks
DarrenCode: Select all
SWITCH ($item_number){
case "stm_test":
$months = 1;
$sched = 31;
break;
case "mttm_test":
$months = 3;
$sched = 92;
break;
case "ltsm_test":
$months = 6;
$sched = 184;
break;
case "am_test":
$months = 12;
$sched = 365;
break;
default:
$months = 1;
$sched = 31;
}
//$months = 1; // 3 or 6, or 9, or 12
//sets up the 7 day schedule
$now = time();
$day = $now + 7*24*60*60;
$cutoff = strtotime("+$months months");
while ($day <= $cutoff) {
$date = date('Y-m-d', $day);
$insert = "INSERT INTO daily_data SET subscr_id='$subscr_id', date='$date'";
mysql_query($insert);
$day = $day + 7*24*60*60;
}
//then create a daily schedule in the excercise table
for($i=0;$i<=($sched);$i++)
mysql_query("INSERT INTO exercise_data SET subscr_id='$subscr_id', date=date_add(now(),INTERVAL LAST_INSERT_ID() DAY)");
//then create a daily schedule in the food and diet table
for($i=0;$i<=($sched);$i++)
mysql_query("INSERT INTO food_data SET subscr_id='$subscr_id', date=date_add(now(),INTERVAL
LAST_INSERT_ID() DAY)");feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]