【问题标题】:PHP Booking timeslotPHP 预约时间段
【发布时间】:2011-05-29 14:33:26
【问题描述】:

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

  1. Bookslot(存储所有 id - id_bookslot、id_user、id_timeslot)
  2. 时间段(以 15 分钟间隔存储所有时间,例如:09:00、09:15、09:30 等)
  3. 治疗师(存储所有治疗师详细信息)
  4. 用户(存储所有成员详细信息)

    ID_BOOKSLOT ID_USER ID_THERAPIST ID_TIMESLOT

    1           10          1        1  (09:00)  
    2           11          2        1  (09:00)  
    3           12          3        2  (09:15)
    4           15          3        1  (09:00)
    

现在,我的问题是,当我想回显数据时,它会不断显示时间段重复:

            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 显示了 3 次,我想要如下所示的内容

           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"

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

【问题讨论】:

    标签: php database-design


    【解决方案1】:
    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 ;
    

    测试:

    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
    

    【讨论】:

    • 嗨达米尔,感谢您的回答。但我从未使用过 COALENSE 功能?那是什么?从未在数据库中使用过 MAX?对于“可用”,它是否从数据库中检索?
    • 无论如何,我如何回显数据库记录以返回结果?
    • @boyee007, coalesce(Thera_A, 'available') 表示IF Thera_A is not null then Thera_A else 'available'
    • @boyee007 以小步骤进行测试,首先是子查询。删除 max() 和 group by 并查看结果。然后添加 max() 并分组。然后添加外部查询。如果您查看返回的结果,这很容易。
    • @boyee007,SO 是社区帮助网站;所以,把你的问题留在这里——其他一些人也可能受益。
    【解决方案2】:

    我猜你需要 GROUP BY id_timeslot,然后检查哪些治疗师已预订(或未预订)。

    为避免复杂的查询,请制作表格“约会”(id、u_id、t_id、start、stop、day)... 然后,您可以使用 BETWEEN start/stop 和 WHERE day = someday... 打印特定日期或时间跨度的约会...

    【讨论】:

      猜你喜欢
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 2016-02-19
      • 2014-10-12
      相关资源
      最近更新 更多