gpt4 book ai didi

php - 如何打印没有数据表的页面

转载 作者:可可西里 更新时间:2023-10-31 23:02:52 24 4
gpt4 key购买 nike

我正在尝试从 sql 中打印数据以用于记录目的,但我使用的是数据表,因此当我尝试单击打印时,记录并未显示所有内容。它只显示数据表第 1 页的当前数据。我将如何做?另外,当我尝试打印它时,显示屏还显示了 php.ini 的包含函数。允许使用 Javascript 解决方案。这是我的代码

        <?php include ('sidebar.php'); ?>
<main id="playground">
<?php include ('header.html'); ?>

<div class="container-fluid">
<div class="row">
<div class="col-md-12">


<section class="panel panel-info">
<header class="panel-heading">
<h4 class="panel-title">List of employees</h4>
</header>
<div class="panel-body">

<?php
include('configuration.php');
$sql = "SELECT firstname, lastname, status, idnumber FROM employees ORDER BY lastname ASC";
$result = $conn->query($sql);
?>
<table class="table table-striped datatable" id="datatables" >
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>ID Number</th>
</tr>
</thead>



<?php
if ($result->num_rows > 0) { // output data of each row?>
<tbody>
<button onclick="myFunction()">Print this page</button>
<?php while($row = $result->fetch_assoc()) {
if($row['status']=='p'){
?>

<?php { //this form will display the set of pending applications

echo'<tr>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['idnumber'] . '</td>';
echo'</tr>';
}
?>

<?php } //if statement
} //while statement
?>
</tbody>
</table>


<?php
}else {
echo "0 results";
}
?>



</div>
</section>
<!-- end of STRIPED ROWS TABLE -->

</div> <!-- / col-md-12 -->
</div> <!-- / row -->
</div> <!-- / container-fluid -->


</main> <!-- /playground -->




<?php include ('notifications.html'); ?>



<div class="scroll-top">
<i class="ti-angle-up"></i>
</div>
</div> <!-- /animsition -->


<script>
function myFunction() {
window.print();
}
</script>

</body>
</html>

最佳答案

请使用

$('#datatables').DataTable( {
buttons: [
'print'
]
} );

请查看DocumentReference

关于php - 如何打印没有数据表的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34566705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com