Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 选择不同日期2小时之间的所有记录_Php_Mysql_Datetime - Fatal编程技术网

Php 选择不同日期2小时之间的所有记录

Php 选择不同日期2小时之间的所有记录,php,mysql,datetime,Php,Mysql,Datetime,我想创建一个彩票系统,为此我需要生成所有彩票。但我需要检查是否以前为用户生成了票证,为此我需要选择12:00(中午)和下一个12:00(中午)之间的记录 但是如果我是第二天上午11:00,请求做什么 如果用户检查票据是否在中午后创建,请求是什么 我尝试过这个方法,但我认为这不是正确的方法: $current_date = date("Y-m-d H:i:s"); $current_hour = date("H"); if($current_hour>=12) { //Noon is

我想创建一个彩票系统,为此我需要生成所有彩票。但我需要检查是否以前为用户生成了票证,为此我需要选择12:00(中午)和下一个12:00(中午)之间的记录

但是如果我是第二天上午11:00,请求做什么

如果用户检查票据是否在中午后创建,请求是什么

我尝试过这个方法,但我认为这不是正确的方法:

$current_date = date("Y-m-d H:i:s");
$current_hour = date("H");
if($current_hour>=12)
{
    //Noon is done, we select ticket
    $stmt = $databaseConnection->prepare("SELECT * FROM loto WHERE user_name=:username AND date_game > :current_date ");
    $stmt->bindParam(":current_date",$current_date,PDO::PARAM_STR);   $stmt->bindParam(":username",$username,PDO::PARAM_STR);
}
else
{
    //Before noon, we select ticket
}

查找函数NOW()的用法,INTERVAL和BETWEEN。你可以用日期和时间来“计算”。这很简单。你能解释一下你的想法吗?我很确定在彩票中,两个人可以拥有相同的彩票,而且奖品是共享的,你是说抽奖吗?我只想检查一下用户生成的彩票是否在12:00到12:00之间完成。现在我使用的是:$stmt=
$databaseConnection->prepare(“从loto中选择*,其中user\u name=:用户名和日期\u NOW()之间的游戏-间隔24小时到NOW()”但这并不好