我通过从我的数据库中读取数据来创建一个表,并且它正确显示它但是当我想添加DataTables插件时它不起作用。
这就是我的尝试:
<?php
include_once 'classes/baza.class.php';
include_once 'classes/prijava_odjava.class.php';
$naziv = "Ispis";
include '_header.php'
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://datatables.net/download/build/nightly/jquery.dataTables.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link href="http://datatables.net/download/build/nightly/jquery.dataTables.css" rel="stylesheet" type="text/css">
<nav class="large-6 row">
<table id='tablica'>
<?php
$baza = new Baza();
$upit = "SELECT * FROM user";
$rezultat = $baza->selectDB($upit);
//echo "";
echo "<tr><th>ID</th><th>Korisničko ime</th><th>Lozinka</th><th>Email</th><th>Last update</th><th>Aktivacijski kod</th><th>Aktiviran</th></tr>";
while ($row = mysqli_fetch_assoc($rezultat)) {
echo "<tr><td>" . $row['id_user']
. "</td><td> " . $row['username']
. "</td><td> " . $row["password"]
. "</td><td> " . $row["email"]
. "</td><td> " . $row['last_update']
. "</td><td> " . $row['aktivacijski_kod']
. "</td><td> " . $row['aktiviran']
. "</td><td></td></tr>";
}
//echo ""; //Close the table in HTML
?>
</table>
</nav>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script>
$(document).foundation();
$(document).ready(function () {
$("#tablica").DataTable({
"bSort": true,
"bPaginate": true,
"bFilter": true
});
});
</script>
<?php include '_footer.php'; ?>
此代码仍显示数据库中的数据,但不使用DataTable插件。就像它甚至不存在一样。
编辑: 添加了thead和tbody,但我遇到了同样的问题。
echo "<thead><tr><th>ID</th><th>Korisničko ime</th><th>Lozinka</th><th>Email</th><th>Last update</th><th>Aktivacijski kod</th><th>Aktiviran</th></tr></thead>";
echo "<tbody>";
while ($row = mysqli_fetch_assoc($rezultat)) {
echo "<tr><td>" . $row['id_user']
. "</td><td> " . $row['username']
. "</td><td> " . $row["password"]
. "</td><td> " . $row["email"]
. "</td><td> " . $row['last_update']
. "</td><td> " . $row['aktivacijski_kod']
. "</td><td> " . $row['aktiviran']
. "</td></tr>";
}
echo "</tbody>";
答案 0 :(得分:1)
根据https://datatables.net/manual/installation
要使DataTable能够增强HTML表,该表必须是 有效的格式良好的HTML,带有标题(thead)和正文(tbody)。 也可以使用可选的页脚(tfoot)。
您必须使用<thead>
和<tbody>