gpt4 book ai didi

php - 动态列 php、mysql 和 DataTables

转载 作者:行者123 更新时间:2023-11-29 10:34:48 24 4
gpt4 key购买 nike

我已尝试以下代码,但似乎无法显示数据表功能。我所看到的只是无边框静态表中的数据。

有人可以告诉我我的代码有什么问题吗?我想将 CDN 主机用于 css 和 javascript。我还需要一个本地 .js 文件吗?

 <!DOCTYPE html>
<html>
<head>
<title>Mobile Apps</title>
<link href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<table id="mobileapp">
<thead>
<th>Trans ID</th>
<th>App Date</th>
<th>Name</th>
<th>City State Zip</th>
</thead>
<tbody>
<!-- Fetch from Db -->
<?php
$db_host = 'serverA'; // Server Name
$db_user = 'root'; // Username
$db_pass = ''; // Password
$db_name = 'mrd_log'; // Database Name
//connect to database
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

//database connection error check
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}

//SQL data query to retrieve data
$sql = "SELECT registration.tran_id, registration.application_date, registration.name1, registration.cityline1 FROM registration WHERE registration.application_date < curdate()";

//Assign results to variable
$query = mysqli_query($conn, $sql);

while ($result = mysqli_fetch_array($query)) {

echo "
<tr>
<td>".$result['tran_id']."</td>
<td>".$result['application_date']."</td>
<td>".$result['name1']."</td>
<td>".$result['cityline1']."</td>
</tr>";
}
?>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#mobileapp').DataTable();
});


</body>
</html>

最佳答案

在 HTML 头中包含 DataTable JS 库:

<link  href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">              
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>

关于php - 动态列 php、mysql 和 DataTables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46638281/

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