PHP+CSS实现打印简单数据报表功能_[PHP教程]
PHP+CSS实现打印简单数据报表功能
功能:实现打印日报表的功能,定义了专门的打印样式,隐藏了不该打印的控件并实现了分页打印功能,表名:rec 字段:rec_id,rec_po,rec_part,rec_plant,rec_vendor,rec_pur_um,rec_req_date,rec_req_qty,rec_rec_qty,rec_iqc_date,rec_notes
完整源代码如下:
Daily Report
body {
margin: 9px;
padding: 0;
color: black;
text-decoration: none;
font-size: 10pt;
font-family: "Courier New";
}
input {
font-family: Arial;
}
th {
font-weight: normal;
border-bottom: 1px solid black;
}
td {
font-size: 9pt;
font-family: "Courier New";
}
td.pod {
font-size: 11pt;
font-family: "Courier New";
}
th.pod {
font-size: 11pt;
font-family: "Courier New";
}
td.endline {
border-top: 1px solid black;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
.center {
text-align: center;
}
.top {
vertical-align: top;
}
@media print {
.noprint { display: none; }
}
define ("SP10" ,' ');
global re;
function db_link()
{
access_id = "root";
access_pwd = "831025";
db_name = "inv";
@ db = mysql_connect('localhost', access_id, access_pwd) or
die("Could not connect to database. Please contact with IT supporting team ASAP.");
mysql_query("SET NAMES 'GBK'");
mysql_select_db(db_name);
return db;
}
link=db_link();
?>
Program :
bom_report.php
Date/Time :
Plant :
SJ01
User Name :
liuxueping
Receiving Date :
Page :
1
rec_sql = "SELECT * FROM rec WHERE rec_plant = 'SJ01' ORDER BY rec_id DESC";
rec_res = mysql_query(rec_sql);
rec_num = mysql_num_rows(rec_res);
if(rec_num>0){
for (i = 0; i < rec_num; i++){
re++;
rec_row = mysql_fetch_array(rec_res);
part_sql = "SELECT pt_desc FROM part WHERE pt_part='".rec_row['rec_part']."' ";
part_res = mysql_query(part_sql);
part_row = mysql_fetch_array(part_res);
echo'
'.(i+1).'
'.rec_row['rec_vendor'].'
'.rec_row['rec_part'].'
'.part_row['pt_desc'].'
'.rec_row['rec_pur_um'].'
'.substr(rec_row['rec_req_date'], 0, 10).'
'.number_format(rec_row['rec_req_qty'], 2).'
'.number_format(rec_row['rec_rec_qty'],2).'
'.number_format(rec_row['rec_rec_qty'],2).'
'.substr(rec_row['rec_iqc_date'], 0 ,10).'
'.rec_row['rec_notes'].'
';
//每页只打印10条记录,如果记录数是10的倍数后,显示'***End of Report***'并开始打印下一页
if(re%10 == 0 and re != rec_num){
echo'
*** End of Report ***
';
//下一页开始打印
echo '
Program :
bom_pro.php
'.SP10.'
Date/Time :
'.date("Y-m-d").'/'.date("H:i:s").'
Plant :
SJ01
'.SP10.'
User Name :
lucas
Receiving Date :
'.date('Y-m-d').'
'.SP10.'
Page :
';echo re/10+1;echo'
';
}
}
echo'
*** End of Report ***
onclick="window.print()">
onclick="window.close()">
';
}
else{
echo'