简体   繁体   English

预订系统php mysql

[英]booking system php mysql

This is what I need: 这就是我需要的:

Print the ID of employees who has availability on a certain span of time, eg: from 28-12-2014 10:00 to 28-12-2014 11:00 These employees might be doing some other activities which are on a BD according to this picture: Table of ongoing activities 打印在特定时间段内有空的员工的ID,例如: from 28-12-2014 10:00 to 28-12-2014 11:00这些员工可能正在做一些其他活动,这些活动根据BD此图: 正在进行的活动表

What I have: 我有的:

At the moment I am comparing those dates vs the one that I need, row by row like this: 目前,我正在逐行比较这些日期和我需要的日期:

$sql_reservas="SELECT * FROM `Reservas` WHERE `ID_Empleado`= 2";
        $result_reservas = mysqli_query($link,$sql_reservas);    
        if(mysqli_num_rows($result_reservas)>0){        
        foreach($result_reservas as $row_reservas ) {          
        ongoing_start       = new DateTime("{$row_reservas['Inicio']}"); //28-12-2014 11:45 then 28-12-2014 09:45
        ongoing_finish      = new DateTime("{$row_reservas['Libre']}"); //28-12-2014 13:45 then 28-12-2014 10:45
        new_activity_start  = $_POST['date'] //28-12-2014 10:00
        new_activity_finish = $_POST['date2'] //28-12-2014 11:00
        If(new_activity_start<ongoing_start && new_activity_finish<ongoing_start ){
        //I have space before the ongoing activities
        echo $row_reservas['ID_Empleado'];
        }elseif(new_activity_start>ongoing_finish && new_activity_finish>ongoing_finish) {
        //I have space after the ongoing activities
       echo $row_reservas['ID_Empleado'];       
       }else{
        //overlaps with the compared one
        echo "not available";

        }}}

The problem: 问题:

When there is just one booking (like the ID 3 or 4 or 5...) everything works fine, BUT when there are 2 or more bookings (like with ID 2) it will still let me book the space because one of the two ongoing activities is not overlapping with the requested date 当只有一个预订(例如ID 3或4或5 ...)时,一切正常,但是当有两个或更多预订(例如ID 2)时,我仍然可以预订该空间,因为这两个是其中之一正在进行的活动与请求的日期不重叠

I hope you can help me with this. 希望您能帮到我。 thanks 谢谢

what i understand, that you need to get all employee IDs in that table, that are FREE in a period of time, 据我了解,您需要获取该表中的所有员工ID,并且在一段时间内是免费的,

what about using between ? between使用呢?

try this: 尝试这个:

select ID_Empleado FROM `Reservas` WHERE 
(CAST('$date' AS DATETIME) NOT BETWEEN Inicio and Libre)
AND 
(CAST('$date2' AS DATETIME) NOT BETWEEN Inicio and Libre)

$date and $date2 are values from $_POST[] $date$date2$_POST[]中的值

Explanation: get employee's ID that needed-start-date and needed-end-date not falling between start-date and end-date of an activity 说明:获取员工ID,该ID的开始日期和结束日期不在活动的开始日期和结束日期之间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM