2

我想开发一个 iOS 应用程序,它可以在上午 8:00 到晚上 8:00 的 15 分钟间隔内为您提供预约时间,条件是您的预约时间为 1 小时 30 分钟。

该应用程序将下载此时间并将它们粘贴到 tableView 中。其他约会的时间(开始、结束时间、持续时间)将存储在 MySQL 数据库中。我想用 PHP 或 SQL 计算它(我不知道,哪个更好)。

到目前为止,这是我的想法:

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;

}

好吧,这段代码不包含顶部的给定条件,但如果我可以构建一个工作代码,我想添加它。

4

1 回答 1

1

在 SQL 中,我计算了时间间隔(我已根据您的要求进行了修改)

declare @time datetime
declare @Etime datetime
declare @Interval datetime

set @time='2013-12-18 08:00:00.000'

While @time<'2013-12-18 16:00:00.000' 
Begin
    set @Etime=convert(varchar(25), dateadd(mi,90,@time))
    set @Interval = convert(varchar(25), dateadd(mi,15,@Etime)) 

    select @time as StartTime, @Etime as EndTime, @Interval as Interval

    set @Time = @Interval
End

在我的项目中,我将其用作

declare @time datetime
declare @Etime datetime
declare @Interval datetime

set @time='2013-12-18 08:00:00.000'

IF OBJECT_ID('dbo.timetable', 'U') IS NOT NULL
  DROP TABLE dbo.timetable 

create table timetable  (StartTime datetime, EndTime datetime, Interval datetime)

While @time<'2013-12-18 16:00:00.000' 
Begin
    set @Etime=convert(varchar(25), dateadd(mi,90,@time))
    set @Interval = convert(varchar(25), dateadd(mi,15,@Etime)) 

    insert into timetable values(@time, @Etime, @Interval)

    set @Time = @Interval
End

然后

select * from timetable

希望这可以帮助

于 2013-12-18T11:03:00.537 回答