php - 从 Laravel 中的存储过程列中动态显示包含列的 HTML 表
问题描述
我有一个带有一些参数的存储过程。我想显示带有列名的 HTML 表应该是存储过程中的列名。我怎样才能做到这一点?
示例:我正在执行我的存储过程 CALL_LIST, 2020-06-01, 2020-06-03。这里 CALL_LIST 是存储过程名称,2020-06-01 和 2020-06-03 是参数。
存储过程的结果将是这样的
+---------+-------------+-----------+-----------+
| Emp_Code | 01-06-2020 | 02-06-2020| 03-06-2020|
+----------+------------+-----------+-----------+
| 1 | 10:00 | 09:00 | 10:00 |
| 2 | 10:00 | 10:00 | 10:00 |
| 3 | 10:00 | 10:00 | 10:00 |
+----------+------------+-----------+-----------+
我的要求是根据传递给存储过程的日期创建动态列。就像这里我传递了 2020-06-01 和 2020-06-03,所以需要生成 3 个动态列与值。如果我通过 2020-06-01 和 2020-06-10,则必须生成 10 个动态列并显示值。
例子
<table>
<thead>
<tr>
<th>Emp Code</th>
<?php $begin = new DateTime($datefrom);
$end = new DateTime($dateto);
$end = $end->modify('+1 day');
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval, $end);
foreach ($daterange as $date_val) {
<th scope="col">$date_val->format('d-m-Y')</th>
} ?>
</tr>
</thead>
<tbody><?php foreach ($data as $val) { ?>
<tr>
<td>{{$val->Emp_Code.}}</td>
</tr><?php } ?>
</tbody>
</table>
如何显示存储过程中的列值?
解决方案
我得到了结果
<table>
<thead>
<tr>
<th>Emp Code</th>
<?php $begin = new DateTime($datefrom);
$end = new DateTime($dateto);
$end = $end->modify('+1 day');
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval, $end);
foreach ($daterange as $date_val) {
<th scope="col">$date_val->format('d-m-Y')</th>
}
$dates = array();
foreach ($daterange as $key => $date) {
$dates[$key] = $date->format('Y-m-d');
} ?>
</tr>
</thead>
<tbody><?php foreach ($data as $val) { ?>
<tr>
<td>{{$val->Emp_Code}}</td>
<?php foreach($dates as $val){
<td>{{$row->{$val}}}</td>
<?php } ?>
</tr><?php } ?>
</tbody>
</table>
推荐阅读
- java - @RequestScoped + 新线程
- nginx - Nginx:SSL握手中的对等关闭连接,同时SSL握手到上游
- javascript - 如何在所有代码执行之前停止响应,使用异步等待
- html - 给定最大宽度时如何保持比例
- excel - 在 Excel 连接中插入 ASCII 字符
- html - 如何在 3dcart/Shift4shop 中自定义订阅时事通讯按钮?
- r - 虹膜残差矩阵
- javascript - 在不重新渲染组件的情况下使用状态在反应 js 中单击按钮切换类
- javascript - 从 div 元素中删除元素
- html - VBA 网页抓取问题 - 如何使用 html 结构(href / child/)导航特定网页