关于这个问题..
我试过 'GROUP BY' id_timeslot 仍然没有工作,因为它只显示预订的时间段不可用
我尝试了该解决方案,但给了我一个错误并且不太明白如何使用“coelence”
table timeslot (id_timeslot integer);
table doctor (id_doctor integer);
table bookslot (id_bookslot, id_doctor, id_timeslot integer);
insert into doctor (id_doctor)
values (1 = doc_A), (2 = doc_B), (3 = doc_C);
insert into TimeSlot (id_timeslot)
values (1 = 10:00:00), (2 = 10:15:00), (3 = 10:30:00), (4 = 10:45:00);
insert into bookslot (id_doctor,id_timeslot)
values (1,1), (1,5), (2,1), (2,4), (3,1);
加入mysql表
$q = $mysqli->query("SELECT * FROM bookslot
RIGHT JOIN timeslot ON bookslot.id_timeslot = timeslot.id_timeslot
LEFT JOIN doctor ON bookslot.id_doctor = doctor.id_doctor ");
回显结果并检查它是否与今天的日期匹配或设置为可用
while($r = $q->fetch_array(MYSQLI_ASSOC)) :
echo '<tr>';
echo '<td align="center">' . $r['times'] . '</td>';
if($r['booked_date'] == date('Y-m-d') && $r['id_doctor'] == 1):
echo '<td><a href="#available" class="booked">booked</a></td>';
else :
echo '<td><a href="#" class="available">available</a></td>';
endif;
if($r['booked_date'] == date('Y-m-d') && $r['id_doctor'] == 2):
echo '<td><a href="#available" class="booked">booked</a></td>';
else :
echo '<td><a href="#" class="available">available</a></td>';
endif;
if($r['booked_date'] == date('Y-m-d') && $r['id_doctor'] == 3):
echo '<td><a href="#available" class="booked">booked</a></td>';
else :
echo '<td><a href="#" class="available">available</a></td>';
endif;
echo '</tr>';
endwhile;
网页结果
我希望结果看起来像:
id_timeslot doc_A doc_B doc_C
----------------------------------------------
1 booked booked booked
2 available available available
3 available available available
4 available booked available
5 booked available available
请任何其他解决方案!