简体   繁体   English

如何根据要求在当天给予条件

[英]how to give condition on day according to requirement

Here I am developing a logic, In which i want to give condition on Hour as per requirement, Example: Consider, 在这里我正在开发一个逻辑,其中我想按照要求给出小时条件,例如:考虑,

case 1: If hours is in between 17 to 20 then it will perform operation on date as date-1 情况1:如果小时在17到20之间,那么它将在日期执行操作为date-1

case2: If not it will show date as it is case2:如果没有,它会显示日期

following query I have design but it doesn't work..:( provide me better solution...Thank You! 以下查询我有设计,但它不起作用.. :(为我提供更好的解决方案......谢谢!

<?php
$mysqli = mysqli_connect('localhost','root','','company');
if (mysqli_connect_errno($mysqli)){
    echo "Failed to connect to MySQL:".mysqli_connect_error();
  }
$arr=array();

$query=mysqli_query($mysqli, "SELECT substr(date,1,2) as DAY,substr(date,4,2) as MONTH,substr(date,7,4) as YEAR 
from tbl_users
where substr(time,1,2)=17 OR substr(time,1,2)=18 OR substr(time,1,2)=19 OR substr(time,1,2)=20 AND id=3");

while($d=mysqli_fetch_array($query, MYSQL_ASSOC))
{
     $arr[]=$d['DAY'];
     $arr[]=$d['MONTH'];
     $arr[]=$d['YEAR'];
     $arr[]=$d['HOUR'];
     $arr[]=$d['MINUTE'];

}
$time=$arr[3]-1;
echo $time;
?>

Following my comment, you must check the condition at the PHP level rather than on queries. 根据我的评论,您必须检查PHP级别的条件而不是查询。 retrieve date and time from table and then check for condition on values retrieved 从表中检索日期和时间,然后检查检索到的值的条件

$query=mysqli_query($mysqli, "SELECT date, time from tbl_users where id=3");

while($d = mysqli_fetch_array($query, MYSQL_ASSOC))
{
   $day = date('D', strtotime($d['date']));
   //or you may use substr here instead of writing them in queries
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM