我需要填充 DIV 容器,即使用jQuery DataTable创建一个表。问题是这个例子对我不起作用。我看到的不是格式化的表格,而是没有任何 jQuery DataTable 插件元素的未格式化表格。
下面显示的 php 文件位于文件夹中main/tables
,而所有脚本位于main/scripts/media
.
那么,我的代码实际上有什么问题?
<?php
include_once 'include/DatabaseConnector.php';
$query2="SELECT * FROM resources;";
$result2=DatabaseConnector::ExecuteQueryArray($query2);
?>
<script type="text/javascript" src="../scripts/media/js/jquery.dataTables.min.js"></script>
<script src="../scripts/media/js/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript" src="../scripts/media/js/complete.js"></script>
<script type="text/javascript" src="../scripts/media/jsjquery.dataTables.js"></script>
<script type="text/javascript" src="../scripts/media/js/jquery.dataTables.columnFilter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
<div>
<h1>Employees</h1>
<table width="100%">
<tr>
<td>
<div class="scrollbar">
<table id="example" border="0" cellspacing="2" cellpadding="2" width = "100%">
<thead>
<tr>
<th scope="col">Reg</th>
<th scope="col">Title</th>
<th scope="col">Availability</th>
<th scope="col">Latitude</th>
<th scope="col">Longitude</th>
<th scope="col">Average Speed (km/h)</th>
</tr>
</thead>
<tbody>
<?php foreach ($result2 as $row):?>
<tr class="alternate">
<td><?php echo $row['resReg']; ?></td>
<td><?php echo $row['resTitle']; ?></td>
<td><?php echo $row['resAvailability'] ? 'Yes' : 'No';?></td>
<td><?php echo $row['resLatitude']; ?></td>
<td><?php echo $row['resLongitude']; ?></td>
<td><?php echo $row['resAvgSpeed']; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</td>
</tr>
</table>
</div>