I am looking into a ROTA for my work and I have a function that inserts data about annual leave request. This was one line per request and included a start and end date recorded as UNIX time.
However i have now worked out that i need to record each day as a seprate entry in the mysql table, so there will not be a start or end date just a date effected, still unix.
This will require a loop to add a entry per day between the start and end date. i have never used a loop so any help would be appriciated.
this is the function i currently have.
private function Leave() {
if(isset($_POST["Leave"]) && !empty($_POST['timestampS']) && !empty($_POST['timestampE'])) {
$this->user = $this->db->real_escape_string($_POST['user']);
$this->leave_start = strtotime($_POST['timestampS']);
$this->leave_end = strtotime($_POST['timestampE']);
$this->leave_type = $this->db->real_escape_string($_POST['Leave']);
$this->leave_now = strtotime($_POST['now']);
$this->leave_tm = $this->db->real_escape_string($_POST['TM']);
$query_leave_insert = $this->db->query("
INSERT INTO LEAVE (Unique_Id, User_id, start_date, end_date, status, date_added, added_by, verifying_tm) VALUES
('NULL', '".$this->user."', '".$this->leave_start."', '".$this->leave_end."', '".$this->leave_type."', '".$this->leave_now."', '1', '".$this->leave_tm."')
");
if($query_leave_insert) {
$this->messages[] = "<p>Leave successfully updated</p>";
} else{
$this->errors[] = "<p>Sorry there was a problem, Please try again</p>";
}
}
}
The leave start and end timestampS and timestampE are populated by the user using a java calendar in a html textbox. the leave type is a dropdown box and is a number between 10-19. The rest are hidden boxes populated by stored session details, all with a submit button.