php - 只分页一次

标签 php html css

我有一个打印一堆收据的 PHP/HTML 页面。我试图在每次实际打印时让它分页。我已经尝试了几种样式和类代码,但我能做的最好的就是让它在第一个之后中断,但它永远不会重复。 IOW 我希望它在每次打印代码中引用的表格后分页。

enter code here
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"         "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<style type="text/css">
@media all {
.page-break { display: none; }
}

@media print {
.page-break { display: block; page-break-before: always; }
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>North Atlanta Riding Club</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style45 {
    color: #FF0000;
    font-weight: bold;
    font-style: italic;
}
-->
</style>
</head>

<body>
<?php 
do{
        //THIS SEES IF THE LOGGED IN MEMBER HAS CONFIRMED CLOTHING
        $colname_confirmed = "1";
        if (isset($row_roster['key1'])) {
          $colname_confirmed = (get_magic_quotes_gpc()) ? $row_roster['key1'] : addslashes($row_roster['key1']);
        }
        mysql_select_db($database_connection1, $connection1);
        $query_confirmed = sprintf("SELECT * FROM clothingorder WHERE who = %s AND confirmed = 'Y' ORDER BY key1 ASC", $colname_confirmed);
        $confirmed = mysql_query($query_confirmed, $connection1) or die(mysql_error());
        $row_confirmed = mysql_fetch_assoc($confirmed);
        $totalRows_confirmed = mysql_num_rows($confirmed);

        if($totalRows_confirmed<>0){?>

                    <table width="990" border="0" align="left" cellpadding="0" cellspacing="0">
                      <!--DWLayoutTable-->
                      <tr>
                        <td width="990" height="31" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
                      </tr>
                      <tr>
                        <td height="83" valign="top">
                          <table border="1" align="left" cellpadding="2" cellspacing="0" bordercolor="#000000">
                            <tr bgcolor="#FFFFFF" class="style5">
                              <td colspan="9"><p>Member- <strong><?php echo $row_roster['fname']." ".$row_roster['lname']; ?><br>
                                  </strong>Telephone- <strong><?php echo $row_roster['tel']; ?></strong>&nbsp;&nbsp;&nbsp;Email- <strong><?php echo $row_roster['email']; ?></strong><br>
                                  Address- <br>
                                  <strong>
                                  <?php if($row_roster['add1']<>''){echo $row_roster['add1']."<br>";} ?>
                                  </strong>              
                                  <strong>
                                  <?php if($row_roster['add2']<>''){echo $row_roster['add2']."<br>";} ?>
                                  </strong>
                                  <strong>
                                  <?php if($row_roster['city']<>''){echo $row_roster['city'].", ";} ?>
                                  </strong>
                                  <strong>
                                  <?php if($row_roster['state']<>''){echo $row_roster['state']." ";} ?>
                                  </strong>
                                  <strong>
                                  <?php if($row_roster['zip']<>''){echo $row_roster['zip'];} ?>
                                  </strong><br>
                              </p>
                                </td>
                            </tr>
                            <tr bgcolor="#FFFFFF" class="style5">
                              <td><div align="center"><strong>Qty</strong></div></td>
                              <td><strong>Item</strong></td>
                              <td><strong>PO?</strong></td>
                              <td><div align="center"><strong>Paid?</strong></div></td>
                              <td><div align="center"><strong>Mens/Womens</strong></div></td>
                              <td><div align="center"><strong>Style</strong></div></td>
                              <td><div align="center"><strong>Cut</strong></div></td>
                              <td><div align="center"><strong>Size</strong></div></td>
                              <td><div align="center"><strong>Price</strong></div></td>
                      </tr>
                            <tr bgcolor="#FFFFFF" class="style5">
                              <td colspan="8"><div align="right">Narc Membership </div></td>
                              <td><div align="center">
                              <?php if($row_roster['paid']=="Y"){echo "Paid";$total=0;}else{echo "$".$row_dues['dues'];$total=$row_dues['dues'];} ?></div></td>
                            </tr>
                            <?php 
                            do { 
                                    $colname_item = "1";
                                    if (isset($row_confirmed['item'])) {
                                    $colname_item = (get_magic_quotes_gpc()) ? $row_confirmed['item'] : addslashes($row_confirmed['item']);
                                    }
                                    mysql_select_db($database_connection1, $connection1);
                                    $query_item = sprintf("SELECT key1, item, price, free FROM clothing WHERE key1 = %s", $colname_item);
                                    $item = mysql_query($query_item, $connection1) or die(mysql_error());
                                    $row_item = mysql_fetch_assoc($item);
                                    $totalRows_item = mysql_num_rows($item);
                                    ?>
                            <tr class="style5">
                              <td><div align="center"><?php echo $row_confirmed['qty']; ?></div></td>
                              <td><?php echo $row_item['item']; ?></td>
                              <td><div align="center"><span class="style45">
                                <?php if($row_confirmed['postorder']=='Y'){?>YES<?php }?></span></div></td>
                              <td><div align="center"><?php echo $row_confirmed['paid']; ?></div></td>
                              <td><div align="center"><?php echo $row_confirmed['mf']; ?></div></td>
                              <td><div align="center"><?php echo $row_confirmed['style']; ?></div></td>
                              <td><div align="center"><?php echo $row_confirmed['cut']; ?></div></td>
                              <td><div align="center"><?php echo $row_confirmed['size']; ?></div></td>
                              <td><div align="center">
                              <?php if($row_confirmed['price'] == 0){echo "Free";
                                }else{
                                    if($row_confirmed['paid']=="Y"){echo "Paid";}else{echo $row_confirmed['price'];$total = $total + $row_confirmed['price'];}
                                    } ?>

                              </div></td>
                            </tr>
                            <?php 

                            } while ($row_confirmed = mysql_fetch_assoc($confirmed)); ?>
                                    <tr bgcolor="#FFFFFF" class="style5">
                              <td colspan="8"><div align="right"><em><strong>Total Owed</strong></em></div></td>
                              <td><div align="center" class="style6"><em><strong><?php echo "$".$total.".00";?></strong></em></div></td>
                            </tr>
                    </table>
                    </td>
                      </tr>
                    </table>
                    <div class="page-break"></div>
        <?php 
        }

}while($row_roster = mysql_fetch_assoc($roster));
?>
</body>

最佳答案

我也发现@media print {} 中的分页符“非常不稳定”!事实上,到目前为止,发现@media 打印完全是片状的。 float 效果不佳,一些样式细节似乎没有按预期显示。似乎浏览器对“打印”的支持乏善可陈。我正在开发一个应打印名牌的应用程序,而精度对于放置和调整大小至关重要。我几乎要放弃 @media print {} 样式,尽管我希望它看起来像在线网络一样,但要按照我的设想进行打印。可能不得不接受它看起来像徽章。我正在使用每 6 个“记录”添加一个分页符类 div 的代码(徽章在 3、4“x 3”w 的 2 列中向上排列 6 个)。

如果像我一样,您无法找到使用@media print {} 的方法,是否可以在您打算打印时在屏幕上显示收据?也可能是您的解决方法,直到(如果)浏览器 catch w3c 约定。我很想找到一个很好的出版物来解释什么对@media 打印样式有效和无效,否则屏幕样式应该有效。

关于php - 只分页一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22737918/

相关文章:

php - 如何在 phpmyadmin 中运行 PDO 准备语句(带有命名占位符)?

javascript - 无论区域设置如何,HTML 输入[日期] 默认为 mm/dd/yyyy

javascript - 通过spotify发送歌曲信息

javascript - 根据点击事件滑动div

html - 背景图像停止出现在 IE8 中

Javascript正则表达式替换-出现随机数字

Javascript 代码有时会打印在屏幕上

php - 为什么 php 在 die(); 之后继续解释?

php - Laravel 5.3 从数据库结果创建多维数组

html - 将多行文本与图像垂直对齐