我正在尝试使打印按钮用于从与mysql数据库相关的表中导入数据。我使用的页面是data_buku.php,其中包含用于在表格中显示数据的代码。我还使用模态来添加新数据,这些新数据在同一文件中包含模态代码。 因此,当我导入data_buku.php时,还将打印包含表单的代码模式。
这是我的代码
<?php
include "action.php";
$dataDB = new DataDB();
$no = 1;
$datas = $dataDB->getData();
?>
<div class="panel box-shadow-none content-header"></div>
<div class="col-md-12 top-20 padding-0">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading"><h3>Data kategori</h3></div>
<div class="panel-body">
<a class="btn btn-round btn-primary" data-target="#add" data-toggle="modal"><i class="fa fa-plus" aria-hidden="true"></i> Tambah Data</a>
<a class="btn btn-round btn-primary" href="print.php?file=pages/data_master/data_buku/data_buku.php"><i class="fa fa-print"></i> Print </a><br><br>
<div class="responsive-table">
<table id="datatables-example" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th>No.</th>
<th>Kode Buku</th>
<th>Judul Buku</th>
<th>Nama Rak</th>
<th>Nama Penulis</th>
<th>Kategori</th>
<th>Nama Penerbit</th>
<th>Tahun</th>
<th>No. ISBN</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php foreach ($datas as $data) { ?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data['kode_buku'] ?></td>
<td><?php echo $data['judul_buku'] ?></td>
<td><?php echo $data['nama_rak'] ?></td>
<td><?php echo $data['nama_penulis'] ?></td>
<td><?php echo $data['nama_kategori'] ?></td>
<td><?php echo $data['nama_penerbit'] ?></td>
<td><?php echo $data['tahun'] ?></td>
<td><?php echo $data['no_isbn'] ?></td>
<td>
<a class="btn btn-xs btn-warning" href="?hal=edit_data_buku&kode_buku=<?php echo $data['kode_buku'];?>" alt="Edit Data"><i class="glyphicon glyphicon-pencil"></i></a>
<a class="btn btn-xs btn-danger" href="?hal=data_buku&delete=<?php echo $data['kode_buku'];?>" alt="Delete Data" onclick="return confirm('ANDA YAKIN AKAN MENGHAPUS DATA?')"> <i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- modal -->
<div id="add" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Tambah Data</h4>
</div>
<div class="modal-body">
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="judul_buku" placeholder="Judul Buku" required >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
<input type="submit" name="createData" class="btn btn-primary" value="Simpan">
</div>
</form>
</div>
</div>
</div>
</div>
<-- code php for insert to db -->
<?php
if(isset($_POST['createData'])){
$judul_buku = $_POST['judul_buku'];
$input = $dataDB->createData($judul_buku);
if($input == "sukses"){
?>
<script> location.replace("/perpus/admin/?hal=data_buku"); </script>
<?php
}
else {
?>
<script> alert('Data gagal ditambahkan')</script>
<?php
}
}
?>
print.php中的此代码用于将页面导入excel
<?php
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=download.xls");
$file = $_GET['file'];
include $file;
?>
有人,有可能限制进口吗?还是有其他解决方案?请告诉我。谢谢!