在PHP和MYSQL中的2个数据库表中查询2次

时间:2017-04-24 08:07:39

标签: php mysql

在PHP和MYSQL中的2个数据库表中查询2次

这是我的数据库

| time1   | time2 |
| 15:00   | 17:00 |

然后我想显示它是否已经在查询代码中的2个数据库表之间有一段时间

例如

 $a = '14:00';
 $b = '16:00';
if($a <= $time1 && $b >=$time2){
   echo 'it already has a time in the database';

 }else{
 echo 'dont have time in the database';
  }

 output will be
  it already has a time in the database

提前致谢 我想要查询该样本。再次感谢

2 个答案:

答案 0 :(得分:0)

WHERE '$a' >= time2 OR '$b' <= time1

答案 1 :(得分:0)

我认为你正在比较错误的数据类型...你在mysql里面使用的是Witch数据类型吗? (时间,日期时间,字符串...)

如果('时间'改变你的代码就像这样):

$a = strtotime('14:00');

然后比较它。

否则{请提供您的数据库数据类型。}

相关问题