![](/img/trans.png)
[英]Display the MySQL table using PHP and JavaScript in datatable
[英]How to retrieve table rows in MySQL using PHP and Display it with Javascript?
我正在尝试使用MYSQL中的数据库表加载并在html的数据表中显示它。 但由于某些原因,即使我在数据库中测试我的查询,也没有检索到任何数据。 有人可以帮我解决这个问题吗? 见下面的代码:
function loadAccountsList() { $.ajax({ type: 'POST', url: '../back_php_Code/pAdminList.php', dataType: 'json', contentType: 'application/json; charset=utf-8', success: function(response) { $('#AccountList').empty(); var cells = eval("(" + response + ")"); alert(cells); for (var i = 0; i < cells.length; i++) { $('#AccountList').append('<tr data-empid="' + cells[i].Code + '">' + '<td style="font-size:11px; text-align:center;">' + cells[i].name + '</td>' + '<td style="font-size:11px; text-align:center;">' + cells[i].typeofloan + '</td>' + '<td style="font-size:11px; text-align:center;">' + cells[i].bank + '</td>' + '<td style="font-size:11px; text-align:center;">' + cells[i].amount + '</td>' + '<td style="font-size:11px; text-align:center;">' + cells[i].status + '</td>' + '</tr>'); } }, error: function(error) { console.log(error); } }); }
<script type="text/javascript" src="..\\jsScripts\\jsAdminList.js"></script> <div class="card"> <div class="card-block"> <div class="dt-responsive table-responsive"> <table id="alt-pg-dt" class="table table-striped table-bordered nowrap"> <thead> <tr> <th>CI_CODE</th> <th>Fullname</th> <th>Type of Loan</th> <th>Bank</th> <th>Amount</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody id="AccountList"></tbody> <tfoot> <tr> <th>CI_CODE</th> <th>Fullname</th> <th>Type of Loan</th> <th>Bank</th> <th>Amount</th> <th>Status</th> <th>Action</th> </tr> </tfoot> </table> </div> </div> </div>
谢谢并恭祝安康,
我认为你错误地成功了。 您不需要在响应中添加引号并分配给单元格变量
success: function (response) {
// Now your `response` is in json which which is an array of objects
// emptying table which is fine
$('#AccountList').empty();
// you are using jquery so you can simply iterate through queries like this
$(response).each(function(index, row){
$('#AccountList').append('<tr data-empid="' + row.empID + '">'
+ '<td style="font-size:11px; text-align:center;">' + row.badgenum + '</td>'
+ '<td style="font-size:11px; text-align:center;">' + row.empName + '</td>'
+ '<td style="font-size:11px; text-align:center;">' + row.groupName + '</td>'
+ '<td style="font-size:11px; text-align:center;">' + row.email + '</td>'
+ '<td style="font-size:11px; text-align:center;">' + row.contact_no + '</td>'
+ '<td style="font-size:11px; text-align:center;">' + row.empStatus + '</td>'
+ '</tr>');
});
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.