I'd like to develop an iOS Application, which gives you available times for an appointment in a 15 Minutes Interval from 8:00 am to 8:00 pm with the condition that your appointment will have an 1h 30min duration.
The App will download this times and will paste them into a tableView. Times of other appointments (beginning, end time, duration) will be stored in a MySQL-Database. I want to calculate it with PHP or SQL (I don't know, what is better).
This is my idea, so far:
function easyfunction($day, $cutter, $open, $closed) {
//Create new Array
$frei = array();
//Calculate times for the $frei-Array
for($time = $open; $time > $closed; $time=$time + date_create_from_format('H:i', 0:15);) {
array_push($frei, $time);
}
//MySQL-Request
$connect = mysqli_connect("host", "DB", "Password")or die("Fehler beim Verbinden mit der Datenbank");
mysqli_select_db("Appointments")or die("Database doesnt exist");
$sql = "SELECT * FROM termine WHERE friseuse=$cutter AND date=$day";
$ergebnis = mysqli_query($sql);
while($row = mysqli_fetch_array($ergebnis)){
//Write Appointment and duration in variables
$datetime = $row->datetime;
$duration = $row->duration;
//Calculate Ending
$terminende = $datetime + $duration;
// Create Search Array
$search = array();
//Filter all values from $frei
$search = array_search($datumzeit < $frei, $frei);
$search = array_search($ende > $frei , $frei);
unset($frei[$search]);
}
//Return all times
return $frei;
}
Well, this code doesn't contain the given condition on the top, but I want to add it, if I can build a working code.
In SQL I have calculated time interval as(i have modified according to your requirement)
In my project I have used it as
and later
hope this helps