【发布时间】:2020-02-24 19:39:28
【问题描述】:
我想以如下格式导出数据表
------------------------------------
sr | id | name | phone | photo
------------------------------------
1 | s12 | John | 9874563210 | Image
-------------------------------------
像这样:
HTML 代码:
<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Sr. No</th>
<th>id</th>
<th>Name</th>
<th>Phone Number</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$sr=0;
$sql = "SELECT * FROM `user` ORDER BY `name ASC ";
$result = mysqli_query ($connect, $SQL);
if (mysqli_num_rows ($result) > 0) {
while ($fieldinfo=mysqli_fetch_object ($result)
{
$sid=$fieldinfo->sid;
$name=$fieldinfo->name;
$phone=$fieldinfo->phone;
$photo = $fieldinfo->photo;
$sr=$sr+1;
?>
<tr>
<td><?PHP echo $sr?></td>
<td><?PHP echo $sid?></td>
<td><?PHP echo $name?></td>
<td><?PHP echo $phone?></td>
<td><img src="upload/photo/<?PHP echo $photo;?>" onError="this.onerror=null;this.src='images/placeholder.png';" style="height: 80px;"></td>
</tr>
<?PHP }?>
</tbody>
</table>
如果照片不可用,则onError="this.onerror=null; 将显示占位符。
我的 JavaScript 代码是:
<script>
$('#example23').DataTable({
dom: 'Bfrtip',
buttons: [
{
extend: 'copy',
title: 'Result for <?php echo $_SESSION["pd_name"]?>'
},
{
extend: 'excel',
title: 'Result for <?php echo $_SESSION["pd_name"]?>'
},
{
extend: 'pdf',
title: 'Result for <?php echo $_SESSION["pd_name"]?>'
},
{
extend: 'print',
title: 'Result for <?php echo $_SESSION["pd_name"]?>'
}
],
"pageLength": 50,
"oLanguage": {
"sSearch": "Quick Search / Sorting: "
}
});
</script>
当我导出表格时,照片列仍然为空。但是图像显示在数据表中。我想在我的导出文件 (PDF) 中显示所有图像。我正在使用 datatables.net 库。
【问题讨论】:
标签: javascript html datatables