我在显示数据后在同一页面提交php表单,我想打印它。我能做到这一点。但我想只打印显示在表格中的结果数据。
这是我的页面
<?php
include ("include/dbconnect.php");
include ("include/format.inc.php");
?>
<script>
function myFunction()
{
window.print();
}
</script>
<script src="htmlDatePicker.js" type="text/javascript"></script>
<link href="htmlDatePicker.css" rel="stylesheet">
<script type="text/javascript"><!--
var today = new Date();
DisablePast = false;
range_start = new Date(today.getFullYear(),today.getMonth(),8);
range_end = new Date(today.getFullYear(),today.getMonth(),5);
--></script>
<?php
include ("include/header.inc.php");
if(isset($_POST['submit']))
{
$date1 = $_POST['SelectedDate1'];
$date2 = $_POST['SelectedDate1'];
echo $date1;
echo $date2;
$sql = "select * from addressbook where lindate between '".$date1."' AND '".$date2."' ";
$result = mysql_query($sql) or die (mysql_error());
echo '<table width="90%" align="center" cellpadding="0" border="0">';
while($row = mysql_fetch_assoc($result))
{
echo '<tr><td>' .$row['firstname']. $row['lastname']. '</td>';
echo '<td>' .$row['address']. '</td>';
echo '<td>' .$row['mobile']. '</td>';
echo '<td>' .$row['email']. '</td>';
echo '<td>' .$row['lindate']. '</td>';
echo '<td>' .$row['lintime']. '</td>';
echo '<td>' .$row['louttime']. '</td>';
echo '<td>' .$row['login']. '</td></tr>';
}
echo '</table>';
echo '<button onclick="myFunction()">Print this page</button>';
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
Select Date Range:<br />
<input type="text" placeholder="Click me!" name="SelectedDate1" id="SelectedDate" readonly onClick="GetDate(this);"> TO
<input type="text" placeholder="Click me!" name="SelectedDate2" id="SelectedDate" readonly onClick="GetDate(this);">
<input type="submit" name="submit" value="VIEW DATA" />
</form>
<?php include ("include/footer.inc.php");?>
这里我想只选择表格中的数据。请建议我怎么做
答案 0 :(得分:1)
通过打印样式表可以轻松控制打印的内容。在打印样式表中,您可以使用display:none;在页眉,页脚,菜单等元素或块上。这样,只有您要打印的内容才会被发送到打印机。
本文将帮助您创建打印样式表: http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/
希望这会有所帮助:)
答案 1 :(得分:0)
将表放在div
中,然后使用jquery打印:$("mailcontent").printElement();