Link to home
Start Free TrialLog in
Avatar of zero118
zero118

asked on

Print Headers on Every Page

Now, by no means is PHP hard for me, but people are asking me to take rows of information along with the headers and make them printable.  By this I mean on each 8.5x11" peice of paper should show the continuing rows of information but also repeat the table headers at the top of every page.  I have no idea how this would work since margins would be different, it would depend on the orientation (portrait or landscape), etc.  Below is my code for the section that displays the information.  Any help or ideas would greatly help.  Thanks.

//DISPLAY LIST OF PARTS FOR A SPECIFIC PUMP -- GET $n (name), $m (mfc info), mc (machine time), $p (price), $pi (price inc), ma (material)
//      $w (weight), $u (used in)
//      NUMBER REQUIRED, NAME, AND PART NUMBER ARE AUTOMATIC
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      if ($task == 'fulllistshow' && $n != '') {
      
                        $m = $_POST['m'];
                        $w = $_POST['w'];
                        $mc = $_POST['mc'];
                        $pr = $_POST['pr'];
                        $pi = $_POST['pi'];
                        $ma = $_POST['ma'];
                        $u = $_POST['u'];
                        
      
                        $query_mem_1 = "SELECT `name`, `id`, `noreq`, `desc`, `partnum`, ";
                        if ($m == 1){ $query_mem_1 .= "`mfc`, `mfcdesc`, `mfcprtnum`, "; }
                        if ($w == 1){ $query_mem_1 .= "`lbs`, "; }
                        if ($mc == 1){ $query_mem_1 .= "`mchtime`, "; }
                        if ($pr == 1){ $query_mem_1 .= "`lstprc`, "; }
                        if ($pi == 1){ $query_mem_1 .= "`prcinc`, "; }
                        if ($ma == 1){ $query_mem_1 .= "`matcst`, "; }
                        if ($u == 1){ $query_mem_1 .= "`usdin`, "; }
                        $query_mem_1 .= "CAST(SUBSTRING(`partnum`, LOCATE('-', `partnum`) + 1) AS SIGNED) AS `sort_part` FROM `$parts_database_table` WHERE `name`=\"$n\" ORDER BY `sort_part` ASC";
                        mysql_select_db($database_name, $connection);
                        $mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error());
                        $row_mem_1 = mysql_fetch_assoc($mem_1);
                        $totalRows_mem_1 = mysql_num_rows($mem_1);
                                                      ?>
<head><style>TD.altrow2{background-color: #f7f7f7;}TD.altrow1{background-color: #d9d9d9;}</style></head>
                        <table width="100%" border="0" cellspacing="0" cellpadding="1">
                              <tr>
                                      <td colspan="11" class="prod" style="border-bottom: 2px solid #c0c0c0;"><font face="Tahoma" size="2"><img src="../img/splash-logo.jpg" width="140" height="66" align="bottom" /><strong><font size="3"><?=$n?></font></strong></font><br />
                                    </td>
                              </tr>
                              <tr>
                                  <td width="107" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc; border-left:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Part Number</font></strong>
                                    </td>
                                  <td width="102" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Description<br /></font></strong>
                                    </td>
                                    <td width="72" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">No. Required<br /></font></strong>
                                    </td>
                                    <? if ($m == 1) { ?>
                                    <td width="211" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Manufacturer Information<br /></font></strong>
                                    </td>
                                    <? } ?>
                                    <? if ($pr == 1){ ?>
                                    <td width="97" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">List Price</font></span></strong>
                                    </td>
                                    <? } ?>
                                    <? if ($u == 1) { ?>
                                    <td width="94" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Reference</font></strong>
                                    </td>
                                    <? } ?>
                                    <? if ($w == 1){ ?>
                                    <td width="116" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Weight</font></span></strong>
                                    </td>
                                    <? } ?>    
                                    <? if ($ma == 1){ ?>
                                    <td width="100" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Material Cost </font></strong>
                                    </td>
                                    <? } ?>
                                    <? if ($mc == 1){ ?>
                                    <td width="106" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Machine Time </font></strong>
                                    </td>
                                    <? } ?>
                                    <? if ($pi == 1){ ?>
                                    <td width="106" align="left" valign="top" class="prod" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;"><strong><font face="Tahoma" size="1">Price Increase in % </font></strong>
                                    </td>
                                    <? } ?>
                              </tr>
   
                              <? if ($mem_1){
                              $numOfRows = mysql_num_rows ($mem_1);
                              for ($i = 0; $i < $numOfRows; $i++){
                              $name = mysql_result ($mem_1, $i, "name");
                              $noreq = mysql_result ($mem_1, $i, "noreq");
                              $partnum = mysql_result ($mem_1, $i, "partnum");
                              $desc = mysql_result ($mem_1, $i, "desc");
                              if ($w == 1){$lbs = mysql_result ($mem_1, $i, "lbs");}
                              if ($m == 1){$mfc = mysql_result ($mem_1, $i, "mfc");}
                              if ($m == 1){$mfcprtnum = mysql_result ($mem_1, $i, "mfcprtnum");}
                              if ($m == 1){$mfcdesc = mysql_result ($mem_1, $i, "mfcdesc");}
                              if ($u == 1){$usdin = mysql_result ($mem_1, $i, "usdin");}
                              $id = mysql_result ($mem_1, $i, "id");
                              if ($mc == 1){$mchtime = mysql_result ($mem_1, $i, "mchtime");}
                              if ($ma == 1){$matcst = mysql_result ($mem_1, $i, "matcst");}
                              if ($pi == 1){$prcinc = mysql_result ($mem_1, $i, "prcinc");}
                              if ($pr == 1){$lstprc = mysql_result ($mem_1, $i, "lstprc");}
                              $desc = htmlentities($desc);
                              $mfcdesc = stripslashes($mfcdesc);
                              $alternate = ($i % 2) + 1;   ?>      
                              
                              
                              <tr>
                                  <td width="107" align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-left:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><div align="center"><font face="Tahoma" size="1"><strong><?=$partnum?></strong></font></span></div>
                                    </td>
                                  <td align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$desc?><br /></font>
                                    </td>
                                    <td align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$noreq?><br /></font>
                                    </td>
                                    <? if ($m == 1) { ?>
                                    <td width="211" align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1">name ><?=$mfc?><br />part # ><?=$mfcprtnum?><br />descrip ><?=$mfcdesc?></font></span>
                                    </td>
                                    <? } ?>
                                    <? if ($pr == 1){ ?>
                                    <td width="97" align="right" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1">$<?=$lstprc?></font></span>&nbsp;
                                    </td>
                                    <? } ?>
                                    <? if ($u == 1) { ?>
                                    <td align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$usdin?></font></span>&nbsp;
                                    </td>
                                    <? } ?>
                                    <? if ($w == 1){ ?>
                                    <td width="116" align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$lbs?>lbs</font>&nbsp;</span>
                                    </td>
                                    <? } ?>    
                                    <? if ($ma == 1){ ?>
                                    <td width="100" align="right" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1">$<?=$matcst?></font>
                                    </td>
                                    <? } ?>
                                    <? if ($mc == 1){ ?>
                                    <td width="106" align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$mchtime?></font>
                                    </td>
                                    <? } ?>
                                    <? if ($pi == 1){ ?>
                                    <td width="106" align="left" valign="top" style="border-bottom:1px dotted #cccccc; border-right:1px dotted #cccccc;" class="altrow<?=$alternate?>"><font face="Tahoma" size="1"><?=$prcinc?>&nbsp;</font>
                                    </td>
                                    <? } ?>
                              </tr>
                              <? } ?>
                        </table>
<? }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Avatar of ClickCentric
ClickCentric

Use a code library like ezPDF to create pdf files out of the pages to be printed.  In this way, you can control the sizes of the text and layout directly which will allow you to extrapolate the exact size of the page and maintain uniformity despite the local system settings.  This does have the drawback of requiring a pdf viewer, but these are readily available for free these days for pretty much all current operating systems.  This is realistically about the only way to directly control the sizes properly.  I've seen attempts made via css in html output, but at best it works about 90% of the time as even if you set the sizes for everything, that doesn't mean they'll actually come out that size on the other end because of factors like print resolution and such.
Avatar of zero118

ASKER

I've tried the ezPDF approach but I can't seem to grasp the concept of the code required.  That and I don't think it was installed correctly on my server by my host (I actually had them install it).  Any thoughts?
You're probably going to barf, but here's a solution that worked.  Use MS Word as the rendering engine.  (I suppose you can use OOorg as well.)

First, I created a table in HTML, and opened it in MS Word.  Then I altered it by telling word to show the header line on every page.  Also, make sure your header is tagged with THEAD and TH instead of TR and TD.  It doesn't really matter, but, it's good form.

Second, save out the file as a web page.  Then, use that web page as an output template.

Alter the Content-type of the page to be ms word.  We're going to product MS Word compatible HTML file.

Here it is.  Note that MS Word table lines are numbered: <tr style='mso-yfti-irow:<?php echo $i?>'>


<?php
      header("Content-type: application/msword");
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="test.php-1_files/filelist.xml">
<title>col1</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>HP Authorized Customer</o:Author>
  <o:LastAuthor>HP Authorized Customer</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>1</o:TotalTime>
  <o:Created>2006-12-06T02:10:00Z</o:Created>
  <o:LastSaved>2006-12-06T02:10:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>150</o:Words>
  <o:Characters>857</o:Characters>
  <o:Company> </o:Company>
  <o:Lines>7</o:Lines>
  <o:Paragraphs>2</o:Paragraphs>
  <o:CharactersWithSpaces>1005</o:CharactersWithSpaces>
  <o:Version>11.8036</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:GrammarState>Clean</w:GrammarState>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
      {mso-style-parent:"";
      margin:0in;
      margin-bottom:.0001pt;
      mso-pagination:widow-orphan;
      font-size:12.0pt;
      font-family:"Times New Roman";
      mso-fareast-font-family:"Times New Roman";}
@page Section1
      {size:8.5in 11.0in;
      margin:1.0in 1.25in 1.0in 1.25in;
      mso-header-margin:.5in;
      mso-footer-margin:.5in;
      mso-paper-source:0;}
div.Section1
      {page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
      {mso-style-name:"Table Normal";
      mso-tstyle-rowband-size:0;
      mso-tstyle-colband-size:0;
      mso-style-noshow:yes;
      mso-style-parent:"";
      mso-padding-alt:0in 5.4pt 0in 5.4pt;
      mso-para-margin:0in;
      mso-para-margin-bottom:.0001pt;
      mso-pagination:widow-orphan;
      font-size:10.0pt;
      font-family:"Times New Roman";
      mso-ansi-language:#0400;
      mso-fareast-language:#0400;
      mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>
<body lang=EN-US style='tab-interval:.5in'>

<div class=Section1>

<table>
 <thead>
  <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes'>
   <td valign=top style='padding:.75pt .75pt .75pt .75pt'>
   <p class=MsoNormal><b>col1<o:p></o:p></b></p>
   </td>
   <td valign=top style='padding:.75pt .75pt .75pt .75pt'>
   <p class=MsoNormal><b>col2<o:p></o:p></b></p>
   </td>
  </tr>
 </thead>
<?php for($i=1;$i<200;$i++) { ?>
<tr style='mso-yfti-irow:<?php echo $i?>'>
  <td style='padding:.75pt .75pt .75pt .75pt'>
  <p class=MsoNormal>1</p>
  </td>
  <td style='padding:.75pt .75pt .75pt .75pt'>
  <p class=MsoNormal>2</p>
  </td>
 </tr>
<?php } ?>
</table>


</div>

</body>

</html>

Avatar of zero118

ASKER

JK: Could you or anyone else knowledgable in PHP to Word contact me at sterry @ kerrpumps.com?  I think this may solve my problem but since I don't know the "Ways of Word" I'm getting a little lost.  If you contact me I could really use precise help with the actual file.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ClickCentric
ClickCentric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zero118

ASKER

My page code can be found at http://www.kerrpumps.com/reportcode.xps and the phpinfo for the domain can be found at http://www.kerrpumps.com/phpinfo.php

The exPDF page I wrote I deleted because I was getting nowhere.  It wouldn't even create a blank page.  I would LOVE to create PDFs but I'm a layman when it comes to the code for it.  I've increased the points for this question if anyone can help me incorporate what I have into a PDF that can be switched between landscape and portrait and include the headers on every page.  =-)  (The headers ARE NOT dynamic.  Only the rows are.)

Again, I can be reached at sterry @ kerrpumps.com if need be!
When I go to the url above(http://www.kerrpumps.com/reportcode.xps), all I get is a prompt to download the file and it's full of what looks to be compiled code.  Either it's not being parsed properly on the server side or this isn't standard php.  What exactly is that file supposed to be?
Avatar of zero118

ASKER

Sorry, it's a Windows Vista thing.

http://www.kerrpumps.com/partsreport.pdf
You could use the fpdf library for output to pdf. It's very easy to use and is written in pure PHP so no server alterations needed.

http://www.fpdf.org/