php - 如何在php中比较mysql查询中的时间?
问题描述
我在 php 中有一个脚本。
$id=$_GET['id'];
$endTime=$_GET['endTime'];
$stmt = $con->prepare("SELECT candidateId from Attendence where candidateId=? and startTime>cast(? as time)"); //This is the problem line
$stmt->bind_param("ds", $id,$endTime);
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($var);
$response = array();
$response['success']=false;
//traversing through all the result
if($stmt->fetch())
{
$response['success']=true;
$response['cand']=$var;
}
//displaying the result in json format
echo json_encode($response);
当我在 url 栏中输入它时,这很好用:
http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime='14:30:00'
但是当我将第 3 行更改为
$stmt = $con->prepare("SELECT candidateId from Attendence where candidateId=? and startTime<cast(? as time)");
并输入此网址:
http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime='18:30:00'
它显示 {"success":false}
这是出席表中的条目。
12100116050(candidateId) 15:30:00(startTime) 2019-02-05 OS present 17:30:00(endTime)
谁能告诉我如何解决这个问题?
解决方案
去掉周围的单引号endTime
http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime=18:30:00
否则查询字符串将扩展为:
startTime<cast("'18:30:00'" as time)
转换结果为 NULL。
推荐阅读
- javascript - 无法在我的 Angular 12 应用程序的开发人员工具的源中查看我的 .ts 文件
- twitter-bootstrap - Bootstrap 4 - 在页脚文本之后仅显示当前断点(内联)
- amazon-web-services - Terraform aws_security_group:如何从变量传递入口和出口块?
- c# - 从 httpcontext dotnet 6 获取控制器名称
- spring-boot - JSON解析错误:无效的UTF-8中间,方法POST Spring Boot
- python - tf.keras GradientTape:获取关于输入的梯度(返回 nans)
- angular - Angular - 如何在初始负载上具有由父组件确定的动态负载?
- javascript - 在 React native 中,在同一行文本中使用不同的 fonFamily
- python - 根据 pandas 数据框中的列对行求和
- python - 如何从弹出窗口中抓取数据(我需要抓取仅在单击弹出窗口后才可见的数据,这不是链接)