duanmiyang6201 2014-12-29 09:22
浏览 40
已采纳

预订系统php mysql

This is what I need:

Print the ID of employees who has availability on a certain span of time, e.g: 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

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

I hope you can help me with this. thanks

  • 写回答

1条回答 默认 最新

  • douti9253 2014-12-29 09:56
    关注

    what i understand, that you need to get all employee IDs in that table, that are FREE in a period of time,

    what about using 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[]

    Explanation: get employee's ID that needed-start-date and needed-end-date not falling between start-date and end-date of an activity

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等