Laravel SQL查询午夜未显示

发布于 2025-01-20 02:42:47 字数 641 浏览 0 评论 0原文

我正在制作计划显示系统,并显示渡轮的时间表。我的问题是,如果我不按顺序放置午夜时间,请查询跳过午夜的时间并显示早晨的

例子: -

如果我以这样的方式放置数据

  1. 1:30 AM
  2. 6:30 AM
  3. 7:30 AM,

那么Times可以正确显示,但是如果不是在

  1. 6:30 AM
  2. 7:30 AM
  3. 1:30 AM

上的命令,那么查询会跳过1:30 AM,直接直接进入6:30进行显示。

这是我的Laravel SQL查询: - 如果出发时间大于当前时间,则显示下一个可用的一个

         DB::table('ferries')->groupBy('ferry_name')
        ->whereTime('departure_time', '>', Carbon::now()->toTimeString())
        ->whereIn('schedule_type', ['Weekday'])
        ->where('terminal_name', $terminal_name)->get()->all();

I am making a schedule display system and it shows the schedules of ferries. my problem is if I dont put midnight time in order then query skips midnight time and displays morning instead

EXAMPLE:-

if i put data in order like this

  1. 1:30 am
  2. 6:30 am
  3. 7:30 am

then the times show correctly, but if its not in order

  1. 6:30 am
  2. 7:30 am
  3. 1:30 am

then the query skips the 1:30 am and goes straight to 6:30 to display.

Here is my laravel SQL Query:- if departure time is greater than current time then show the next available one

         DB::table('ferries')->groupBy('ferry_name')
        ->whereTime('departure_time', '>', Carbon::now()->toTimeString())
        ->whereIn('schedule_type', ['Weekday'])
        ->where('terminal_name', $terminal_name)->get()->all();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半枫 2025-01-27 02:42:47

结果集本质上是未排序的,您需要添加排序顺序

这将按升序排序,请参阅 手册

DB::table('ferries')->groupBy('ferry_name')
->whereTime('departure_time', '>', Carbon::now()->toTimeString())
->whereIn('schedule_type', ['Weekday'])
->where('terminal_name',$terminal_name)->orderBy('departure_time')->get()->all()

Resukltsets are by nature unsorted yo you need to add a sorting order

This would sort ascending see manual

DB::table('ferries')->groupBy('ferry_name')
->whereTime('departure_time', '>', Carbon::now()->toTimeString())
->whereIn('schedule_type', ['Weekday'])
->where('terminal_name',$terminal_name)->orderBy('departure_time')->get()->all()
一袭水袖舞倾城 2025-01-27 02:42:47

使用了unique()而不是groupby(),然后订单不确定为什么。

$posts =  DB::table('ferries')->orderBy('departure_time', 'asc')
            ->where('departure_time', '>', Carbon::now()->toTimeString())
            ->whereIn('schedule_type', ['Weekday'])
            ->where('terminal_name', $terminal_name)->get()->unique('ferry_name')->all();

Used unique() instead of groupBy() then the orderBy worked not sure why.

$posts =  DB::table('ferries')->orderBy('departure_time', 'asc')
            ->where('departure_time', '>', Carbon::now()->toTimeString())
            ->whereIn('schedule_type', ['Weekday'])
            ->where('terminal_name', $terminal_name)->get()->unique('ferry_name')->all();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文