php - 当数据库中有数据时,数据表不起作用
问题描述
当 Jquery 数据表插件具有按日期从数据库中选择的数据时,它不起作用。但如果表中没有数据,它就可以工作。这里有一些代码
从控制器中的数据库表中选择所有数据:
$inbound['inbound'] = DB::table('REPORT_INBOUND')
->where('regdate', '=', date('Y-m-d', strtotime("2019-05-21")))
->get();
return view('/traffic', $inbound, $outbound);
我确实复制粘贴了必要的脚本,例如:
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<table id="ahhhaa" width="90%" class="table table-striped table-bordered table-hover display">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>RegDate</th>
<th>HPMN Code</th>
<th>Country</th>
<th>HPMN Name</th>
</tr>
</head>
<tbody>
@foreach($inbound as $value)
<tr class="table table-hover">
<td>{{ $value->id }}</td>
<td>{{ $value->regdate }}</td>
<td>{{ $value->hpmn_code }}</td>
<td>{{ $value->country }}</td>
<td>{{ $value->hpmn_name }}</td>
@endforeach
</tbody>
</table>
$(document).ready(function () {
$('#ahhhaa').DataTable()
});
有什么错误吗?
解决方案
也许是因为你没有关闭你的thead
.
如果没有解决,请修复此问题并发表评论。
<table id="ahhhaa" width="90%" class="table table-striped table-bordered table-hover
display">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>RegDate</th>
<th>HPMN Code</th>
<th>Country</th>
<th>HPMN Name</th>
</tr>
</thead><!-- Add this Line -->
<tbody>
loop...
</tbody>
希望这有效!
推荐阅读
- python - 复利计算器在 Python 中存在问题
- scala - 幻影中的 Cassandra 健康检查
- pysimplegui - 使用循环生成帧:PySimpleGUI
- asp.net - 适用于旧版 SQL Server 数据库的 .NET 框架或 .NET Core for Web API
- python - .str.split() 正在删除最后一个字符
- namecheap - 为什么我的 DNS 记录对某些人不起作用?
- imageresizer - 将 ImageFlow 服务器与多个 Azure 容器一起使用
- python - 即使多次安装和卸载,导入请求也会导致错误
- python - 如何在 Matplotlib 的子图中添加多个条形图
- web - How does a website serve a list of data to the user for page/slider content?