我有一个像这样的MySQL表:
| rsid | rsuser | rsintime | rsouttime | rsroom |
| ---- | ------ | ------------------- | ------------------- | ------ |
| 1 | Nick S | 2014-10-14 11:17:34 | 2014-10-14 12:18:06 | 1 |
| 2 | Mike G | 2014-10-15 10:18:38 | 2014-10-15 11:19:00 | 1 |
我想用当前时间搜索输入/输出时间。所以,用英语,如果房间很忙,请回声"忙碌"。如果可用,回声"房间是免费的,直到"下一次。
这是我到目前为止所做的:
<?php
$con=mysqli_connect("008.178.143.7","roomapp","password","roomapp");
$testschedulesql = "SELECT (NOW() > rsintime AND NOW() < rsouttime) as res_rm from raRmSchedule";
$testscheduleqry = mysqli_query($con, $testschedulesql);
$testschedule = mysqli_num_rows($testscheduleqry);
if($testschedule > 0){
echo 'Busy';
}
else{
echo 'Not';
}
?>
这总是返回真实。
答案 0 :(得分:0)
如果您要在MySQL中解决它,可能是这样的:
SELECT IF (NOW() > rsintime AND NOW() < rsouttime)
THEN 'Busy'
ELSE
THEN CONCAT('Room is free until ',
(SELECT rsintime
FROM rooms
WHERE rsid <> rsintime
ORDER BY rsintime
LIMIT 0, 1))
AS room_status
WHERE rsid = theIdOfTheRoom
这只是一个指南。我不确定它是否有效,因为我现在无法测试它,可能会写一个更好的解决方案。但希望它可以让你滚动。