首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  HTML/JS/CSS技术专区 » [原创]循环解决打印所遇到的问题!  


  作者:风向北吹
  注册时间:2006-02-20
  主题/回复:10/7
  积分:457
  等级:★★☆(五级)
  称号:略有小成

  0313yy@sina.com
  78140037
  www.

 

 发表:2006-04-01 04:29:19 阅读 2492 次 回复 3 次 得分0  |   字号 字色
[原创]循环解决打印所遇到的问题!
<?php require_once('Connections/connmyguding.php'); ?>
<?php
mysql_select_db($database_connmyguding, $connmyguding);
$query_Recordset1 = "SELECT * FROM user";
$Recordset1 = mysql_query($query_Recordset1, $connmyguding) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-size: 30px;
font-family: "华文隶书";
font-weight: bold;
}
.style6 {font-size: 14px; font-family: "楷体_GB2312"; }
.style10 {font-size: 14px; font-family: "幼圆"; font-weight: bold; }
.style11 {
font-size: 14px;
font-weight: bold;
}
.style12 {
font-size: 14px;
font-family: "幼圆";
}
.style13 {font-size: 12px}
-->
</style>
</head>

<body>
<?php
for($i=0;$i<$totalRows_Recordset1/3;$i++)
{

echo "<table width='906' height='364' border='0' cellpadding='0' cellspacing='0'>";
echo  "<tr>";
echo  "<td width='902' height='77'><div align='center'><span class='style1'>固 定 资 产 计 提 表</span></div></td>";
echo  "</tr>";
echo  "<tr>";
echo  "<td height='43'><div align='center' class='style12'>年 月</div></td>";
echo   "</tr>";
echo  "<tr>";
echo  "<td><span class='style6'>填报单位:</span></td>";
echo  "</tr>";
echo  "<tr>";
echo  "<td><table width='904' border='2' cellpadding='0' cellspacing='0' bordercolor='fda316' style=' border-collapse: collapse;'>";
echo  "<tr>";
echo  "<td width='73' height='40'><div align='center'><span class='style10'>设备编号</span></div></td>";
echo  "<td width='73'><div align='center'><span class='style10'>启用日期</span></div></td>";
echo  "<td width='80'><div align='center'><span class='style10'>设备名称</span></div></td>";

echo   "</tr>";
echo   "<tr>";
for ($j=0;$j<=2;$j++)
{$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$pagesum=$row_Recordset1['user_level'];
$pagesum=$pagesum+$row_Recordset1['user_level'];
echo   "<td height='25'><div align='center'><span class='style13'>".$row_Recordset1['user_id']."</span></div></td>";
echo   "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_qiyongdate']."</span></div></td>";
echo   "<td><div align='center'><span class='style13'>".$row_Recordset1['user_level']."</span></div></td>";

echo   "</tr>";
  }   
echo   "<tr>";
echo   "<td height='25'>";
echo   "<td> </td>";
echo   "<td><div align='center'><span class='style13'>$pagesum</span></div></td>";
echo   "</tr>";
echo   "</table></td>";
echo   "</tr>";
echo   "<tr>";
echo   "<td>第 页 </td>";
echo   "</tr>";
echo   "</table>";
}
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

————————————————————————————
还是循环的问题,为了实现报表打印,我想到了用循环的办法进行web打印。先是一个大循环,每页三条记录,$i<$totalRows_Recordset1/3得到页数,循环得到每页表格格式。然后里面又嵌套了一个小循环,使得纪录依次分布到各页。
问题一:这个思路正确吗?有更好的写法吗?
问题二:我希望在每页的最下一行做一个“本页合计”使用了$pagesum,可是总是计算的不对,请指教。
问题三:我希望在最后一页多家一栏“总计”,我想应该是有个判断吧,请教这个判断怎么写?“总计”这个变量怎样得到?谢谢!!!
 
 1#楼  
 
  回复人:风向北吹
  注册时间:2006-02-20
  主题/回复:10/7
  积分:457
  等级:★★☆(五级)
  称号:略有小成

   
 1#楼 发表于2006-04-01 05:51:57  评分:× 

自己解决了问题二。
for ($j=0;$j<=2;$j++)
{$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$pagesum=$row_Recordset1['user_level'];
$pagesum=$pagesum+$row_Recordset1['user_level'];
————————————————————————
改为
for($i=1;$i<=$totalRows_Recordset1/3;$i++)
{
$pagesum=0;
——————————————————
for ($j=1;$j<=3;$j++)
{$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$pagesum=$pagesum+$row_Recordset1['user_level'];
 2#楼  
 
  回复人:风向北吹
  注册时间:2006-02-20
  主题/回复:10/7
  积分:457
  等级:★★☆(五级)
  称号:略有小成

   
 2#楼 发表于2006-04-05 18:45:28  评分:× 

昨天自己解决了第三个问题,用的是笨方法。但好赖还管用吧。
思路如下:
if $i==最后一页
$j循环3次
加“本页合计”行
else
$j循环2次
加“本页合计”行
加“总计”行

大体思路如上,对此有兴趣的朋友可以联系一起探讨。
 3#楼  
 
  回复人:风向北吹
  注册时间:2006-02-20
  主题/回复:10/7
  积分:457
  等级:★★☆(五级)
  称号:略有小成

   
 3#楼 发表于2006-04-06 23:31:46  评分:× 

<?php
session_start();
$myyear=($_SESSION['MMshbyear']);
$mymonth=($_SESSION['MMshbmon']); 
$tablename=($_SESSION['MMtablename']);
$username=($_SESSION['MM_Username']);
$SHBdanwei=($_SESSION["MMshbdanwei"]);
set_time_limit(0);
?>
<?php require_once('../Connections/connmyguding.php'); ?>
<?php
mysql_select_db($database_connmyguding, $connmyguding);
$query_Recordset1 = "SELECT * FROM $tablename";
$Recordset1 = mysql_query($query_Recordset1, $connmyguding) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-size: 30px;
font-family: "华文隶书";
font-weight: bold;
}
.style6 {font-size: 14px; font-family: "楷体_GB2312"; }
.style10 {font-size: 14px; font-family: "幼圆"; font-weight: bold; }
.style11 {
font-size: 14px;
font-weight: bold;
}
.style12 {
font-size: 14px;
font-family: "幼圆";
}
.style13 {font-size: 12px}
.style15 {font-size: 12px; font-family: "幼圆"; }
-->
</style>
</head>

<body>
<?php
for($i=1;$i<=ceil($totalRows_Recordset1/16);$i++)
{
$pagesum_yuan=0;
$pagesum_yue=0;
$pagesum_nian=0;
$pagesum_lei=0;
$pagesum_jing=0;
echo "<table width='936' height='339' border='0' cellpadding='0' cellspacing='0'>";
echo "<tr>";
echo "<td width='934' height='77'><div align='center'><span class='style1'>固 定 资 产 计 提 表</span></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='43'><div align='center' class='style12'>".$myyear."<strong>年</strong>".$mymonth."<strong>月</strong></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='style6'><strong>填报单位:</strong>燃气销售二分公司".$SHBdanwei."</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><table width='934' border='2' cellpadding='0' cellspacing='0' bordercolor='fda316' style=' border-collapse: collapse;'>";
echo "<tr>";
echo "<td width='73' height='40'><div align='center'><span class='style10'>设备编号</span></div></td>";
echo "<td width='73'><div align='center'><span class='style10'>启用日期</span></div></td>";
echo "<td width='90'><div align='center'><span class='style10'>设备名称</span></div></td>";
echo "<td width='45'><div align='center'><span class='style10'>数量</span></div></td>";
echo "<td width='40'><div align='center'><span class='style10'>使用年限</span></div></td>";
echo "<td width='80'><div align='center'><span class='style11'>原值(元)</span></div></td>";
echo "<td width='67'><div align='center'><span class='style10'>月折旧率</span></div></td>";
echo "<td width='80'><div align='center'><span class='style11'>月折旧额(元)</span></div></td>";
echo "<td width='67'><div align='center'><span class='style10'>年折旧率</span></div></td>";
echo "<td width='80'><div align='center'><span class='style10'>年折旧额(元)</span></div></td>";
echo "<td width='80'><div align='center'><span class='style10'>累计折旧额(元)</span></div></td>";
echo "<td width='80'><div align='center'><span class='style10'>净值(元)</span></div></td>";
echo "</tr>";
echo "<tr>";
if ($i!=ceil($totalRows_Recordset1/16))
{
for ($j=1;$j<=16;$j++)
{
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$pagesum_yuan=sprintf("%.2f",($pagesum_yuan+$row_Recordset1['shb_yuanzhi']));
$pagesum_yue=sprintf("%.2f",($pagesum_yue+$row_Recordset1['shb_yuezhejiu']));
$pagesum_nian=sprintf("%.2f",($pagesum_nian+$row_Recordset1['shb_nianzhejiu']));
$pagesum_lei=sprintf("%.2f",($pagesum_lei+$row_Recordset1['shb_leijizhejiu']));
$pagesum_jing=sprintf("%.2f",($pagesum_jing+$row_Recordset1['shb_jingzhi']));

$sum_yuan=sprintf("%.2f",($sum_yuan+$row_Recordset1['shb_yuanzhi']));
$sum_yue=sprintf("%.2f",($sum_yue+$row_Recordset1['shb_yuezhejiu']));
$sum_nian=sprintf("%.2f",($sum_nian+$row_Recordset1['shb_nianzhejiu']));
$sum_lei=sprintf("%.2f",($sum_lei+$row_Recordset1['shb_leijizhejiu']));
$sum_jing=sprintf("%.2f",($sum_jing+$row_Recordset1['shb_jingzhi']));
echo "<td height='25'><div align='center'><span class='style13'>".$row_Recordset1['shb_id']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_qiyongdate']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_name']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_number']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianxian']."年</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuanzhi']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuezhelv']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuezhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianzhelv']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianzhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_leijizhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_jingzhi']."</span></div></td>";
echo "</tr>";
}
echo "<tr>";
echo "<td height='25'> </td>";
echo "<td> </td>";
echo "<td><div align='center' class='style12'><strong>本页合计</strong></div></td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_yuan."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_yue."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_nian."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_lei."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_jing."</span></div></td>";
echo "</tr>";
}
else
{
for ($j=1;$j<=15;$j++)
{
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$pagesum_yuan=sprintf("%.2f",($pagesum_yuan+$row_Recordset1['shb_yuanzhi']));
$pagesum_yue=sprintf("%.2f",($pagesum_yue+$row_Recordset1['shb_yuezhejiu']));
$pagesum_nian=sprintf("%.2f",($pagesum_nian+$row_Recordset1['shb_nianzhejiu']));
$pagesum_lei=sprintf("%.2f",($pagesum_lei+$row_Recordset1['shb_leijizhejiu']));
$pagesum_jing=sprintf("%.2f",($pagesum_jing+$row_Recordset1['shb_jingzhi']));
$sum_yuan=sprintf("%.2f",($sum_yuan+$row_Recordset1['shb_yuanzhi']));
$sum_yue=sprintf("%.2f",($sum_yue+$row_Recordset1['shb_yuezhejiu']));
$sum_nian=sprintf("%.2f",($sum_nian+$row_Recordset1['shb_nianzhejiu']));
$sum_lei=sprintf("%.2f",($sum_lei+$row_Recordset1['shb_leijizhejiu']));
$sum_jing=sprintf("%.2f",($sum_jing+$row_Recordset1['shb_jingzhi']));
echo "<td height='25'><div align='center'><span class='style13'>".$row_Recordset1['shb_id']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_qiyongdate']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_name']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_number']."</span></div></td>";
if ($j<=$totalRows_Recordset1%16)
{
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianxian']."年</span></div></td>";
}
else
{
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianxian']."</span></div></td>";
}
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuanzhi']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuezhelv']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_yuezhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianzhelv']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_nianzhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_leijizhejiu']."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$row_Recordset1['shb_jingzhi']."</span></div></td>";
echo "</tr>";
}
echo "<tr>";
echo "<td height='25'> </td>";
echo "<td> </td>";
echo "<td><div align='center' class='style12'><strong>本页合计</strong></div></td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_yuan."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_yue."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_nian."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_lei."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$pagesum_jing."</span></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='25'> </td>";
echo "<td> </td>";
echo "<td><div align='center' class='style12'><strong>总计</strong></div></td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$sum_yuan."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$sum_yue."</span></div></td>";
echo "<td> </td>";
echo "<td><div align='center'><span class='style13'>".$sum_nian."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$sum_lei."</span></div></td>";
echo "<td><div align='center'><span class='style13'>".$sum_jing."</span></div></td>";
echo "</tr>";
}

echo "</table></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='28' width='150' valign='middle'><span class='style15'><strong>第</strong>".$i."<strong>页</strong>   <strong>共</strong>".ceil($totalRows_Recordset1/16)."<strong>页</strong>  </span></td>";
echo "</tr>";
echo "</table>";
}

?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>


这是完整的代码.
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.028sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版