wrong dates in a schedule

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bigfella

    wrong dates in a schedule

    Hi Everyone,

    I am using the following code (many thanks for the code folks BTW) to
    generate 3 schedules in three tables one is a schedule with 7 day
    intervals and two are daily schedules.

    The two daily schedules seem to have 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

    Darren

    $now = time();
    $day = $now + 7*24*60*60;
    $cutoff = strtotime("+$mo nths months");
    while ($day <= $cutoff) {
    $date = date('Y-m-d', $day);
    $insert = "INSERT INTO daily_data SET subscr_id='$sub scr_id',
    date='$date'";
    mysql_query($in sert);
    $day = $day + 7*24*60*60;
    }
    //then create a daily schedule in the excercise table
    for($i=0;$i<=($ sched);$i++)
    mysql_query("IN SERT INTO exercise_data SET subscr_id='$sub scr_id',
    date=date_add(n ow(),INTERVAL
    LAST_INSERT_ID( ) DAY)");
    //then create a daily schedule in the food and diet table
    for($i=0;$i<=($ sched);$i++)
    mysql_query("IN SERT INTO food_data SET subscr_id='$sub scr_id',
    date=date_add(n ow(),INTERVAL
    LAST_INSERT_ID( ) DAY)");

  • Gordon Burditt

    #2
    Re: wrong dates in a schedule

    >I am using the following code (many thanks for the code folks BTW) to[color=blue]
    >generate 3 schedules in three tables one is a schedule with 7 day
    >intervals and two are daily schedules.
    >
    >The two daily schedules seem to have out of sync dates at the start of
    >each schedule. The dates look as if they may be dates from the
    >preceding loop.[/color]

    ... date=dateadd(no w(), INTERVAL LAST_INSERT_ID( ) DAY) ...

    This is absolutely wierd. Shouldn't that be INTERVAL 7 DAY?
    After you have a lot of people sign up, LAST_INSERT_ID( ) is going
    to be a couple hundred or thousand, and certainly isn't what you
    want. I also note that you never seem to use $i within the loops.
    Perhaps that's what you want instead of LAST_INSERT_ID( )?

    You also never set $sched.


    [color=blue]
    >I am presuming that I need to reset something after the completion of
    >each loop but I am not sure what.
    >
    >Many thanks
    >
    >Darren
    >
    >$now = time();
    >$day = $now + 7*24*60*60;
    >$cutoff = strtotime("+$mo nths months");
    >while ($day <= $cutoff) {
    > $date = date('Y-m-d', $day);
    > $insert = "INSERT INTO daily_data SET subscr_id='$sub scr_id',
    >date='$date' ";
    > mysql_query($in sert);
    > $day = $day + 7*24*60*60;
    >}
    >//then create a daily schedule in the excercise table
    >for($i=0;$i<=( $sched);$i++)
    > mysql_query("IN SERT INTO exercise_data SET subscr_id='$sub scr_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("I NSERT INTO food_data SET subscr_id='$sub scr_id',
    >date=date_add( now(),INTERVAL
    >LAST_INSERT_ID () DAY)");
    >[/color]

    Gordon L. Burditt

    Comment

    Working...