gpt4 book ai didi

php - 使用 Now() 搜索 MySQL 总是返回 true

转载 作者:行者123 更新时间:2023-11-29 07:50:25 24 4
gpt4 key购买 nike

我有一个像这样的 MySQL 表:

| rsid | rsuser  | rsintime         | rsouttime        | rsroom |
| ---- | ------- | ---------------- | ---------------- | ------ |
| 1 | Nick S | 10/14/2014 11:17 | 10/14/2014 12:18 | 1 |
| 2 | Mike G | 10/15/2014 10:18 | 10/15/2014 11:19 | 1 |
| 3 | Chuck M | 10/14/2014 21:56 | 10/14/2014 22:56 | 1 |
| 4 | Jake B | 10/26/2014 22:14 | 10/26/2014 23:15 | 1 |

我的 PHP 代码是:

<?php
$con=mysqli_connect("0.0.0.0","roomapp","hi","roomapp");
$testschedulesql = "SELECT (NOW() > rsintime AND NOW() < rsouttime) as res_rm from raRmSchedule";
$testscheduleqry = mysqli_query($con, $testschedulesql);
$testschedule = mysqli_num_rows($testscheduleqry);
$testscheduletext = mysqli_fetch_array($testscheduleqry);
echo $testschedule;
if($testschedule > 0){
echo 'Busy';
}
else{
echo 'Not';
}
?>

但是,$testschedule 始终返回总行数。我希望它仅返回当前时间在输入/输出时间内的行。我做错了什么?

最佳答案

您需要一个 where 子句:

SELECT rm.*
from raRmSchedule
WHERE (NOW() > rsintime AND NOW() < rsouttime)

计算行数:

SELECT COUNT(*)
from raRmSchedule
WHERE (NOW() > rsintime AND NOW() < rsouttime)

这将返回一行一列。如果没有匹配,则为 0

您的版本为表中的每一行返回一行。将有一列的值为 01,具体取决于条件是否匹配。

关于php - 使用 Now() 搜索 MySQL 总是返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26580554/

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