I have a series of selects populated with mysql data. Note: Day name is a label
Sunday time_from time_to
Monday time_from time_to
Tuesday time_from time_to
...
Saturday time_from time_to
In the database these are stored in a table called availability whose structure is:
CREATE TABLE `staff_availability` (
`staff_availability_id` int(11) NOT NULL AUTO_INCREMENT,
`staff_id` int(11) NOT NULL,
`day_id` int(1) NOT NULL,
`time_from_id` int(2) DEFAULT NULL,
`time_to_id` int(2) DEFAULT NULL,
PRIMARY KEY (`staff_availability_id`)
);
This table is linked to 2 other tables to get pretty user readable names and times but for the UPDATE / INSERT I wouldn't need those because the selects have their respective time_from_id etc as the value (Except the days which are labels)
My php runs 2 foreach loops - one for time_from and one for time_to which generates selects as follows:
<select id="time_from" class="form-control input-sm" name="time_from">
<option value="null">Not Available</option>
<?php foreach ($this->time_slots as $time) {
if ($time->time_slot_id == $availability->time_from_id) { ?>
<option value="<?php echo $time->time_slot_id; ?>" selected="selected"><?php echo $time->time; ?></option>
<?php } else { ?>
<option value="<?php echo $time->time_slot_id; ?>"><?php echo $time->time; ?></option>
<?php }
} ?>
</select>
The problem: $_POST['time_from'] and $_POST['time_to'] only return one value. How would I return all 7 pairs of selects to update the 7 timeslots in the staff_availability table like this:
day_id time_from_id time_to_id
1 2 14
2 4 14
3 2 14
...