gpt4 book ai didi

php - 预订 session 室;选择给定时间段内的可用房间

转载 作者:行者123 更新时间:2023-11-29 09:41:38 25 4
gpt4 key购买 nike

我正在制作一个 session 室预订系统,您可以在其中选择特定的时间段,然后您应该在那时获得可用的房间。一些表的名称是法语,因此我将在需要时提供 () 之间的含义。我的问题是,当我选择时间时,我什至没有找到可用的房间。我认为我的查询有一些问题。所以,我有一张预订 table 、教授 table 和salle(法语的意思是房间) table 。预约表有以下列:idReservation、dateReservation、hDebut( session 开始时间)、hFin(结束时间),idSalle(房间id)

这里是创建表查询:如果您不明白某些列名可能是谁,请发表评论,就像我用法语所说的那样。

CREATE TABLE `reservation` (
`idReservation` int(11) NOT NULL,
`dateReservation` date DEFAULT NULL,
`hDebut` time NOT NULL,
`hFin` time NOT NULL,
`dateModificationReservation` date DEFAULT NULL,
`motifReservation` varchar(50) NOT NULL,
`idSalle` int(11) NOT NULL,
`idProf` int(11) NOT NULL,
`etatreserv` int(10) NOT NULL
)

etatreserv(2表示等待,1表示拒绝,0表示接受)代表房间的状态,因为用户发送预订房间一段时间的请求,并且管理员可以选择接受/拒绝,即使房间有空

INSERT INTO `reservation`(`idReservation`, `dateReservation`, `hDebut`, `hFin`, `dateModificationReservation`, `motifReservation`, `idSalle`, `idProf`, `etatreserv`) VALUES (1,'2019-06-14','15:00:00','18:00:00','2019-06-09','administrative meeting',1,12,2)
CREATE TABLE `salle` (
`idSalle` int(11) NOT NULL,
`intitule` varchar(40) NOT NULL,
`NumeroSalle` int(255) NOT NULL
)
INSERT INTO `salle` (`idSalle`, `intitule`, `NumeroSalle`) VALUES
(1, 'salle de reunion 1', 1),
(10, 'salle 18', 18);
CREATE TABLE `professeur` (
`idProf` int(11) NOT NULL,
`nomProf` varchar(50) NOT NULL,
`prenomProf` varchar(50) NOT NULL,
`tel` int(10) UNSIGNED NOT NULL,
`email` varchar(255) NOT NULL,
`profpwd` varchar(255) NOT NULL,
`dateAddProf` date NOT NULL,
`dateModificationProf` date NOT NULL,
`idDepart` int(11) NOT NULL
)
INSERT INTO `professeur` (`idProf`, `nomProf`, `prenomProf`, `tel`, `email`, `profpwd`, `dateAddProf`, `dateModificationProf`, `idDepart`) VALUES
(12, 'ddd', 'dd', 444, 'email@email.com', 'pwd', '2019-06-05', '2019-06-05', 5);

我已经尝试过:

SELECT * FROM reservation left OUTER JOIN salle on reservation.idSalle = salle.idSalle WHERE (
(reservation.dateReservation IS NULL)
OR
(reservation.dateReservation != ':dateReservation')
OR
((reservation.dateReservation = ':dateReservation') AND (reservation.hDebut NOT BETWEEN ':hDebut' AND ':hFin') AND (reservation.hFin NOT BETWEEN ':hDebut' AND ':hFin'))
OR
((reservation.dateReservation = ':dateReservation') AND (reservation.hDebut >':hDebut' AND reservation.hFin <':hFin'))
)

然后我尝试了一个更简化的版本:

    dateReservation = ':dateReservation' AND
(hDebut BETWEEN ':hDebut' AND ':hFin' OR hFin BETWEEN ':hDebut' AND ':hFin' OR
(hDebut < ':hDebut' AND hFin > ':hFin'))))```

example :
salle table
idSalle | name
1 |salle de reunion 1
10 |salle18
3 |salle3

reservation table
idReservation|dateReservation|hDebut |hFin |idSalle
1 |2019-06-14 |15:00:00 |18:00:00 |1

if for example i choose dateReservation = 2019-06-14, hDebut=16:00:00,
hFin = 17:00:00 then all i should see are : salle2 and salle3

PS : I'm new to stackoverflow and the syntax highlighting confused me a bit, so I'm sorry if my code doesn't show up as it should.

最佳答案

    DROP TABLE IF EXISTS salle;

CREATE TABLE salle
(salle_id SERIAL PRIMARY KEY
,name VARCHAR(12) UNIQUE
);

INSERT INTO salle VALUES
(1,'salle1'),
(2,'salle2'),
(3,'salle3');


DROP TABLE IF EXISTS reservation ;

CREATE TABLE reservation
(reservation_id SERIAL PRIMARY KEY
,reservation_from DATETIME NOT NULL
,reservation_to DATETIME NULL
,salle_id INT NOT NULL
);

INSERT INTO reservation VALUES
(1,'2019-06-14 15:00:00','2019-06-14 18:00:00',1);

SELECT s.*
FROM salle s
LEFT
JOIN reservation r
ON r.salle_id = s.salle_id
AND reservation_from <= '2019-06-14 17:00:00'
AND reservation_to >= '2019-06-14 16:00:00'
WHERE r.reservation_id IS NULL;

+----------+--------+
| salle_id | name |
+----------+--------+
| 2 | salle2 |
| 3 | salle3 |
+----------+--------+

关于php - 预订 session 室;选择给定时间段内的可用房间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56515003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com