Jump to content

russed

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by russed

  1. Thanks for the assistance have got it working. I have attached the finished function. 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 = $this->db->real_escape_string($_POST['now']); $this->leave_tm = $this->db->real_escape_string($_POST['TM']); $start_range = $this->leave_start; $end_range = $this->leave_end + 86400; // add one day so end of year is correct $this->error_msg = 0; for ($leave_date=$start_range; $leave_date < $end_range; $leave_date = $leave_date + 86400) { $sql = "INSERT INTO `LEAVE` (`User_id`, `date_effected`, `status`, `date_added`, `added_by`, `verifying_tm`) VALUES (".$this->user.", ".$leave_date.", ".$this->leave_type.", ".$this->leave_now.", 1, ".$this->leave_tm.");"; $result = $this->db->query($sql); if ($this->db->affected_rows != 1) $this->error_msg = $this->error_msg + 1; } if ($this->error_msg == 0 ) { $this->messages[] = "<p>Leave successfully updated</p>"; } else{ $this->errors[] = "<p>Sorry there was a problem, " . $this->error_msg . " records failed.<br>Please try again</p>"; } } }
  2. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.