PHP预订时间段

PHP预订时间段,php,database-design,Php,Database Design,我正在开发一个基于时间段的php预订系统,用于日常预订。 我设置了4个数据库表 Bookslot(存储所有id-id\u Bookslot、id\u user、id\u timeslot) 时隙(将所有时间存储在15分钟间隔上,例如:09:00、09:15、09:30等) 治疗师(存储所有治疗师详细信息) 用户(存储所有成员的详细信息) ID\书店ID\用户ID\治疗师ID\时间段 现在,我的问题是,当我想要回显数据时,它会持续显示时间段的重复,例如: thera a

我正在开发一个基于时间段的php预订系统,用于日常预订。 我设置了4个数据库表

  • Bookslot(存储所有id-id\u Bookslot、id\u user、id\u timeslot)
  • 时隙(将所有时间存储在15分钟间隔上,例如:09:00、09:15、09:30等)
  • 治疗师(存储所有治疗师详细信息)
  • 用户(存储所有成员的详细信息)

    ID\书店ID\用户ID\治疗师ID\时间段
  • 现在,我的问题是,当我想要回显数据时,它会持续显示时间段的重复,例如:

                thera a       thera b       thera c
      -------------------------------------------------
     09:00       BOOKED      available      available
     09:00     available       BOOKED       available
     09:00     available     available        BOOKED 
     09:15     available       BOOKED       available
    
    正如你所看到的,09:00放映了三次,我想要下面的内容

               thera a       thera b       thera c
    -------------------------------------------------
     09:00      BOOKED        BOOKED         BOOKED    
     09:15     available      BOOKED       available
    
    加入这张桌子可能有点问题,或者别的什么。 连接表的代码

    $mysqli->query("SELECT * FROM bookslot RIGHT JOIN timeslot ON bookslot.id_timeslot = timeslot.id_timeslot LEFT JOIN therapist ON bookslot.id_therapist = therapist.id_therapist"
    

    如果有人有这个系统的解决方案,请帮助我,我很感激

    我想你需要按id_时隙分组,然后检查哪些治疗师已预约(或未预约)

    为了避免复杂的查询,请进行表“预约”(id、u\u id、t\u id、开始、停止、日期)。。。 然后,您可以使用开始/停止和WHERE day=某天之间的时间间隔打印特定日期或时间跨度的约会

    select 
          id_TimeSlot
        , coalesce(Thera_A, 'available') as Thera_A
        , coalesce(Thera_B, 'available') as Thera_B
        , coalesce(Thera_C, 'available') as Thera_C
    from
    (
        select
          t.id_TimeSlot
        , max(case b.id_Therapist when 1 then 'booked' else null end) as Thera_A
        , max(case b.id_Therapist when 2 then 'booked' else null end) as Thera_B
        , max(case b.id_Therapist when 3 then 'booked' else null end) as Thera_C
        from      TimeSlot  as t
        left join BookSlot  as b on b.id_TimeSlot  = t.id_TimeSlot
        left join Therapist as p on p.id_Therapist = b.id_Therapist
        group by  t.id_TimeSlot
    ) as xx ;
    
    测试:

    返回

    id_TimeSlot  Thera_A    Thera_B    Thera_C
    ----------------------------------------------
    1            booked     booked     booked
    2            available  available  available
    3            available  available  available
    4            available  booked     available
    5            booked     available  available
    

    嗨,达米尔,谢谢你的回答。但我从未使用过COALENSE函数?什么事?从未在数据库中使用过MAX?对于“可用”,它是否从数据库中检索?无论如何,我如何回显数据库记录以返回结果?@boyee007,coalesce(Thera_A,“available”)的意思是
    如果Thera_A不为空,那么Thera_A else“available”
    @boyee007先用子查询进行小步骤测试。删除max()和group by并查看结果。然后添加max()并按分组。然后添加外部查询。如果你看到返回的结果,这很容易。@boyee007,社区帮助网站也是如此;所以,把你们的问题留在这里——其他一些人可能也会受益。
    create table TimeSLot  (id_TimeSLot integer);
    create table Therapist (id_Therapist integer);
    create table BookSlot  (id_Therapist integer, id_TimeSlot integer);
    
    insert into Therapist (id_Therapist)
    values (1), (2), (3);
    
    insert into TimeSlot (id_TimeSlot)
    values (1), (2), (3), (4), (5);
    
    insert into BookSlot (id_Therapist,id_TimeSlot)
    values (1,1), (1,5), (2,1), (2,4), (3,1);
    
    id_TimeSlot  Thera_A    Thera_B    Thera_C
    ----------------------------------------------
    1            booked     booked     booked
    2            available  available  available
    3            available  available  available
    4            available  booked     available
    5            booked     available  available