[eluser]defectivereject[/eluser]
Hello again.
So following on from my last calendar issue, i've gotten stuck adding dates.
All i'm after is a simple "add 1 week onto this date" foreach time the date appears in this loop.
whereas what i am getting is one week added to the original date requested no matter how many times it inserts the line
incoming data:
date_t = Day cell clicked on the calendar //want date intervals adding to this
data_t - meeting/event details
reoccurs = 1,2,3,4,5 e.t.c. as to how many weeks/fortnights you want to book the room
time_t = simply a timeslot someone wants i.e. 9-11 or 130-230 e.t.c.
My current query is as follows
Code:
function add_calendar_events($date, $data, $dateto, $time) {
$i = 1;
$this->db->insert('calendar2', array(
'date_t' => date_to_mysqldatetime($date),
'data_t' => $data,
'reoccurs'=> $dateto,
'time_t' => $time
));
// The above inserts the line into the DB
//The post data['reoccurs'] is a simple 1,2,3,4,5,e.t.c. to say how many weeks the event reoccurs for, next week, 2 weeks, 5 weeks e.t.c.
// There is only one person managing this, so using MAX(id) is fine.
$query = $this->db->query("SELECT max(id) as maxid FROM calendar2"); //selects the line id just added
$row = $query->row_array();
$max_id = $row['maxid'];
$query2=$this->db->query("SELECT date_t, reoccurs FROM calendar2 WHERE id= $max_id");
//selects the date and occurrence factor of the line just added
$row2 = $query2->row_array();
$occurs = $row2['reoccurs']; //occurrence factor
$added_date = $row2['date_t']; //initial date requested
while ($i <= $occurs) { //adds a line for each week requested
++$i;
$this->db->query(
"INSERT INTO calendar2
(date_t,data_t,reoccurs,time_t)
VALUES
(date_add('$added_date', INTERVAL 7 DAY), '$data', '$dateto', '$time')");
}
//date_add adds the seven days on, but its only adding it to the original date.
// I expected that it would loop through each time to pull the MAX(id) and use the date of that one?
}
I can and will add on a check eventually to see if they requested every week or 2 weeks or monthly and then running the query necessary from the form selection to add on 7, 14, or a month days.
Again most queries are done in MYSQL here purely for time factors and will be put into AR (Aside from the date ones as i can't see anything about adding dates in CI?) when done.