通过打印机通过打印功能打印php表 [英] Print php table with Print function via Printer
问题描述
我有以下php表,如何将打印功能仅添加到php表?还有一个按钮,当单击该按钮时,通过打印机打印了下表,我尝试使用"CTRL + P",但只得到了页面示例的html部分,例如页眉,页脚,导航栏,而不是结果php结果
I have the following php table, how do i add print functionality just to the php table? And a button that when clicked, the following table is printed via printer, I tried 'CTRL+P' and I only got the html secton of the page example the header, footer, navigation bar, and not the results php results
<?php
echo "<table border='1' id= results>
<tr>
<th>FILEID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Issue Date</th>
<th>Interest Rate</th>
<th>Terms</th>
<th>Balance Outstanding</th>
<th>Balance Outstanding</th>
<th>New Loan</th>
<th>Principal Repayment for $l_month</th>
<th>Principal Repaid</th>
<th>Balance Outstanding</th>
<th>Interest Payment for $l_month </th>
<th>INTEREST ACCUMULATED DURING FINNANCIAL YEAR</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['app_file_id'] . "</td>";
echo"<td>". $row['app_fname']."</td>";
echo"<td>". $row['app_lname']."</td>";
echo"<td>". $row['commit_date'] ."</td>";
echo"<td>". $row['computer_interest'] ."</td>";
echo"<td>". $row['loan_life'] ."</td>";
echo"<td>". $row['avg(app_ln_amnt)'] ."</td>";
echo"<td>". $row['Balance Outstanding'] ."</td>";
echo"<td>". $row['New Loan'] ."</td>";
echo"<td>". $row['SUM(r.receipt_on_principal)'] ."</td>";
echo"<td>". $row['Principal Repaid'] ."</td>";
echo"<td>". $row['avg(app_amnt_owed)'] ."</td>";
echo"<td>". $row['SUM(r.receipt_on_interest)'] ."</td>";
echo"<td>". $row['Interest Accumilated'] ."</td>";
echo "</tr>";
}
echo "</table>";
?>
推荐答案
PHP不会将事件发送到浏览器.您可以使用Javascript做到这一点.
PHP doesn't send Events to a Browser. You can do that with Javascript.
<input type="button" onclick="window.print()" value="Print Table" />
要隐藏所有其他不想打印的东西,请将其添加到html中:
To hide all the other Stuff you don't want to print add this to your html:
<style media="printer">
.noprint * {
display:none;
}
然后将css类noprint分配给您不想打印的父元素.
And assign the css class noprint to the parent element you don't want to get printed.
未经测试,但这也可以工作:
Not tested but this could work too:
body {
visibility: hidden;
}
.printthis {
visibility: visible;
}
并为您的表提供类printthis,这样就只会打印该表.
And give your table the class printthis and so only the table gets printed.
这篇关于通过打印机通过打印功能打印php表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!