Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP中的当前时间进行搜索?_Php_Mysql_Datetime - Fatal编程技术网

如何使用PHP中的当前时间进行搜索?

如何使用PHP中的当前时间进行搜索?,php,mysql,datetime,Php,Mysql,Datetime,我有一个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 | 20

我有一个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 |
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
我想根据输入/输出时间搜索当前时间。所以,在英语中,如果房间很忙,回声很忙。如果有回音室,回音室在下一个时间之前是免费的

以下是我到目前为止的情况:

<?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';
}
?>

这总是返回为true。

如果要在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 |
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

不过,这只是一个指南。我不确定它是否有效,因为我现在无法测试它,也许可以编写一个更好的来解决这个问题。但希望它能让你开动脑筋。

它应该反过来工作!您先试试,然后发布您已经尝试过的内容,解释为什么它不起作用……我甚至还没有开始。@SinTekSolutions我的答案对您有帮助吗?它让我开始了……谢谢!