【问题标题】:only returning 10 values with no LIMIT set?只返回 10 个没有设置 LIMIT 的值?
【发布时间】:2018-03-28 02:21:50
【问题描述】:

我已经完成了一个功能,用户将选择“从”和“到”日期,它将返回用户选择的日期的值,它会计算当天不同的用户,它还会分组然后计算相同的日期。所以它会返回正确的东西

但我现在面临的问题是它只会返回最大 10 的值,而不是更多。因此,如果我选择 2018 年 1 月 3 日 - 2018 年 15 月 3 日,它只会从 2018 年 1 月 3 日到 2018 年 10 月 3 日返回。为什么会这样?

我的代码如下:

public function viewUniqueVisitorByDate(Request $request, $companyID)
{
$companyID = $this->decode($companyID);

$allUsers = DiraChatLog::whereBetween('date_access', [$request->from, $request->to])->orderBy('date_access', 'asc')->get();
foreach ($allUsers as $key => $users) {
  $dates = strtotime($users->date_access); 
  $newformat = date('Y-m-d',$dates);
  $userDates[$newformat] = $this->getUsers($newformat,$users);
}

dd($userDates);

$user = array_values($userDates);
$dates = array_keys($userDates);
// dd($user, $dates);

$from = $request->from;
$to = $request->to;
// dd($from, $to);

$companyID = $this->encodeID($companyID);

return view('AltHr.Chatbot.viewUniqueVisitor', compact('companyID','from','to', 'dates'))->with('user',json_encode($user,JSON_NUMERIC_CHECK))->with('dates',json_encode($dates,JSON_NUMERIC_CHECK));     
}

private function getUsers($date,$users)
{
$userDates = Carbon::parse($date)->addDay()->toDateTimeString();
// dd($userDates,$date);

$noOfUsers = DiraChatLog::whereBetween('date_access', [$date,$userDates])->get();
// dd($noOfUsers);

return $noOfUsers->groupBy('user_id')->count();
}

数据库表结构

【问题讨论】:

  • 所以您希望它返回 15 但得到 10 条记录?我收到你的问题了吗?
  • @Wils 是的,你是对的!
  • @JohnDoe 数据库中的日期格式,您能否在数据库中再次点击相同的查询,您是否获得 15 条记录
  • 你能告诉我们你的表格结构吗?
  • @saurabhkamble 你是什么意思?但是当我 dd($from,$to);我得到了正确的日期

标签: php arrays laravel date eloquent


【解决方案1】:

如果$request->from$request->to 不是日期时间格式。在每个 where 子句中,应该是。

DiraChatLog::whereBetween(DB::raw('DATE(date_access)'), [$request->from, $request->to])
            ->orderBy('date_access', 'asc')->get();

$noOfUsers = DiraChatLog::whereBetween(DB::raw('DATE(date_access)'), [$date,$userDates])->get();

因为date_access 是日期时间格式。 别忘了声明使用数据库;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多