gpt4 book ai didi

MySQL:我有一个名为 SLOT 的表,其中有两列 DATE 和 TIME,我想以 html 中的表格形式填充数据

转载 作者:行者123 更新时间:2023-11-29 09:58:18 25 4
gpt4 key购买 nike

MySQL 表具有以下结构:

id, date, time

同一日期可能有多个时间,例如:

1, 20-10-1992, 08:00
2, 20-10-1992, 09:00
3, 20-10-1992, 10:00
4, 20-11-1992, 08:00
5, 20-11-1992, 09:00
6, 20-11-1992, 10:00
7, 20-12-1992, 08:00
8, 20-12-1992, 09:00
9, 20-12-1992, 10:00

我想使用 Laravel 框架将 HTML 中的数据制成表格,日期为标题,列/行为时间,因此模板位于 Blade 中。

最佳答案

只需准备一个具有date组的多维数组,date组将具有time组数组。

$results = \DB::table('SLOT')->select('*')->get();
$data = [];

foreach ($results as $result) {
$data[$result->date][$result->time][] = $result;
}

将 $data 发送到您的 View 文件并按如下方式处理

@foreach($data as $date => $dt)
//your <ul> or <div> or container
//$date
@foreach($dt as $time => $details)
//$time
@foreach($details as $detail)
{{$detail->id}}
//put <li> or something related to your design
@endforeach
@endforeach
@endforeach

关于MySQL:我有一个名为 SLOT 的表,其中有两列 DATE 和 TIME,我想以 html 中的表格形式填充数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53476289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com