我想用php替换java脚本以从db填充数据表 或者只是如何使用php从mysql数据库填充此表。 这是数据表: alladmins.php:
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Admins</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="adminTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>ADMIN ID</th>
<th>USER NAME</th>
<th>Password</th>
<th>Delete</th>
</tr>
</thead>
<tbody id="ad">
</tbody>
<tfoot>
<tr>
<th>ADMIN ID</th>
<th>USER NAME</th>
<th>Password</th>
<th>Delete</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>
</div>
<!-- /.col -->
<script>createTable('#adminTable');</script>
这是index.php中的脚本:
<script>
var createTable = function(el){
if ( $.fn.DataTable.isDataTable(el) ) {
$(el).DataTable().destroy();
}
// table: "#adminTable",
$(el+' tbody').empty();
var arrayOfAdmins = [{id:1,username:"asdasd",password:"asd"},
{id:1,username:"asdasd",password:"asd"}];
for (i=0; i<arrayOfAdmins.length;i++){
$("#adminTable").append(
'<tr><td>'+ arrayOfAdmins[i].id
+'</td><td>'+ arrayOfAdmins[i].username
+'</td><td>'+ arrayOfAdmins[i].password
+'</tr>'
);}
$(el).DataTable();
};
$('.tableSearch').val('a').trigger('#adminTable');
$(document).ready(function(e){
var navigate = function(location){
$('#appMain').load(location,function(){
});
};
/* NAVIGATION */
$('ul.treeview-menu a').on('click',function(e){
e.preventDefault();
var location = $(e.target).attr('href');
navigate(location);
});
navigate('templates/index2.php');
});
</script>