MySQLi while loop for recurring event calendar
Hey Jason,
I'm still working on the same page kids_insert_shift_recurring.php, but now I'm trying to get my insert to work correctly.
What I'm going for here is to have the insert behavior write 1 row for every time the event would occur into the kids_programs_shifts table of my database and then stop after 1 year of events have been written.
For example if I created a recurring event for Jan 1st and said it should recur every month on the 1st day. When I hit submit it should write 11 or 12 (not sure if it's going to count the originally created event or overwrite it) events into the kids_program_shifts table and then stop.
Here's what I got so far, but I ain't having much luck.
<?php
if ((((isset($_POST["Submit"]))?$_POST["Submit"]:"") != "")) {
$next_event = strtotime($_GET["Frequency"].' '.$_GET["RecurType"].' FROM '.$_POST["RecurStart"]);
while(date('Y-m-d', $next_event)<strtotime('1 year from '.$_POST["RecurStart"]) && date('Y-m-d', $next_event)<strtotime($_POST["RecurEnd"])){
$InsertQuery = new WA_MySQLi_Query($local_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "kids_program_shifts";
$InsertQuery->bindColumn("kids_program_date", "t", "".((isset($next_event))?$next_event:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
echo $InsertQuery->Statement;
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
// $InsertQuery->redirect($InsertGoTo);
$next_event = strtotime($_POST["Frequency"].' '.$_POST["RecurType"].' FROM '.$next_event);
}
}
?>