PHP reservation time interval

I am developing a php reservation system based on a time interval on a daily basis. Ive configured 4 database tables!

  • Book tray (in which all identifiers are stored - id_bookslot, id_user, id_timeslot)
  • Timeslot (store all the time in the interval of 15 minutes: 09:00, 09:15, 09:30, etc.).
  • Therapist (stores all therapist's data)
  • User (save all details of the participants)

    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)
    

Now, my problem is that it keeps showing repeat for the time interval when I want the data echo to be:

            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

as you can see, 09:00 is shown three times and I want something like below

           thera a       thera b       thera c
-------------------------------------------------
 09:00      BOOKED        BOOKED         BOOKED    
 09:15     available      BOOKED       available

There may be something wrong with joining the table, otherwise. Code for joining the table

$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"

- , , , !

+3
2
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
+2

, GROUP BY id_timeslot, , ( ).

, "" (id, u_id, t_id, start, stop, day)... , BETWEEN start/stop WHERE day = someday...

+1

Source: https://habr.com/ru/post/1781724/


All Articles