Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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 获取在上一小时和当前小时插入MySQL表的值_Php_Mysql_Laravel 5.1 - Fatal编程技术网

Php 获取在上一小时和当前小时插入MySQL表的值

Php 获取在上一小时和当前小时插入MySQL表的值,php,mysql,laravel-5.1,Php,Mysql,Laravel 5.1,我用的是Laravel 5。我想获取在上一个小时和当前一个小时插入MySQL表的行 时间列datetime格式如下:2015-11-11 08:34:25, 我想获取当前时间并获取在当前时间插入表中的数据。我该怎么做 现在我已经编辑了我的代码 现在我已经编辑了 没有错误,但不是在最后一个小时和当前一个小时内获取行我认为这只是一个输入错误:您编写了>whereBetween,而不是->whereBetween我已经解决了这样的问题 enter code here $currentHo

我用的是Laravel 5。我想获取在上一个小时和当前一个小时插入MySQL表的行

时间列datetime格式如下:
2015-11-11 08:34:25
, 我想获取当前时间并获取在当前时间插入表中的数据。我该怎么做

现在我已经编辑了我的代码

现在我已经编辑了


没有错误,但不是在最后一个小时和当前一个小时内获取行

我认为这只是一个输入错误:您编写了
>whereBetween
,而不是
->whereBetween

我已经解决了这样的问题

enter code here 
    $currentHour=carbon::now()->toTimeString();
    $lasthour=carbon::now()->subHour()->toTimeString();

    $RecentTrips=DriverTrips::select('*')
        ->where('driverid',$id)
        ->where('date',$dateoFTrip)
        ->where(function($query){

            $query->orwhere('status','=','accepted')
                  ->orwhere('status','=','late');
        })

        ->where(function($query)use ($currentHour,$lasthour){

            $query ->whereRaw('TIME(time) <?',[$currentHour])
                   ->whereRaw('TIME(time) >?',[$lasthour]);
        })

        ->get();
在此处输入代码
$currentHour=carbon::now()->toTimeString();
$lasthhour=carbon::now()->subHour()->toTimeString();

$RecentTrips=DriverTrips::select(“*”) ->其中('driverid',$id) ->其中('date',$dateoFTrip) ->其中(函数($query){ $query->orwhere('status','=','accepted') ->或其中('status','=','late'); }) ->其中(函数($query)使用($currentHour,$lasthour){
$query->whereRaw('TIME(TIME))因此,您可以使用php的
date()生成日期/时间字符串
函数,然后只需在查询中添加一个WHERE条件,表示
WHERE time>$1小时前
如果提供的代码是文本而不是图像,则会有所帮助。您从代码中得到了什么错误?$RecentTrips=$TripDetails=DriverTrips::select('*')->WHERE('driverid',$id)->WHERE('time','>=','DATE_SUB(NOW(),INTERVAL 1 HOUR')->where('DATE',$dateoFTrip)->where('status','=','accepted')->或where('status','=','late')->get();没有任何错误,但获取的数据持续时间不正确我也用这种方法$daterecent=new DateTime;$daterecent->modify('-3600分钟)$formatted_date=$daterecent->format($Y-m-d H:i:s);$RecentTrips=$TripDetails=DriverTrips::select('*')->where('driverid',$id)->where('time','SQLSTATE[42S22]:未找到列:where子句中的1054未知列'HOUR(time)'(SQL:select*from
Drivertripdetails
where
driverid
=9和
date
=2015-11-11和
status
=accepted或
status
=late和
HOUR(time)
在2015-11-11 13:34:07和2015-11-11 12:34:07之间现在我收到了错误。Thanx请求帮助。您应该使用
DB::raw(“HOUR(time)”)
我无法理解我使用Tripdetails模型访问数据库。请解释一下对不起,我不确定我应该解释什么。$RecentTrips=DriverTrips::select('*')->where('DriverRid',$id)->where('date',$dateoFTrip)->where('status','=','accepted')->where('status','accepted')->或where('status','status','late'))->wherebeen('time',[$currentHour,$lasthour])->get();