显示所有时间约会和预约

时间:2015-12-28 20:11:58

标签: php mysql

我的约会系统有一些经理(例如医生),我打算将所有预约时间显示在一个表格中,这样约会就会被填满或空白,并带有用户名 为约会时间创建一个表:

+-----------+-----------+
| id         | time 
+-----------+------------
| 1         | 10:00     |
| 2         | 10:30     |
| 3         | 11:00     |
| 4         | 11:30     |
| 5         | 12:00     |
| 6         | 12:30     |
| 7         | 13:00     |
| 8         | 13:30     |
| 9         | 14:00     |
+-----------+-----------+

经理表

+-----------+-------------+-----------+
| id         | name       | phone     |
+-----------+-------------+-----------+
| 1         | alex        | 123456    |
| 2         | dany        | 123456    |

用户表:

+----+------+-------+-----------+
| id | manager_id | name | phone |
+----+------------+------+-----------+
| 1  | 1       |   John  | 123456   |
| 2  | 1       |   Sara  | 123456   |
| 3  | 2       |   lorem | 123456   |
+----+------+-------+-----------+

和订单表(用于约会)

+----+------+-------+------------------+-----------+
| id | manager_id | userid  | reserveid| datereserve
+----+------------+------+-------------+-----------+
| 1  | 1       |   1        | 1        |2016/12/28
| 2  | 1       |   2        | 2        |2016/12/28
| 3  | 2       |   3        | 3        |2016/12/28
+----+------+-------+-----------+-----------+------+

现在我想在一个表中显示预约时间,其中约会已填充或用用户名填空 喜欢 : Similar this photo

我在查询中加入了所有表但无法显示类似的照片并获取数据:( 我该如何实现它?

2 个答案:

答案 0 :(得分:0)

我建议另一张桌子

create table status(id int, name varchar(50));

并插入值(1,“reserved”),(2,“free”)。

select t.time, s.name, m.name, u.name, u.phone 
from time t left join status s on t.id = s.id 
left join order o on o.appointmentsid = t.id 
left join manager m on o.manager_id = m.id 
left join users u on o.userid = u.id;

答案 1 :(得分:0)

SELECT 
  m.name,
  a.time,
  u.phone,
  u.name <- if u.name or u.phone is NULL, then appointment is free now
FROM manager as m
CROSS JOIN appointments as a
LEFT JOIN order as o ON o.manager_id = m.id AND o.appointmentsid = a.id 
LEFT JOIN user as u ON u.id =  o.userid

#for some doctor
WHERE m.id = DoctorID