Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rather strange print problem with PHP file. Requesting assistance.

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I've been trying to work on a php sheet used to display the output from a database for our company. Everything seems to be going well so far, but I'm running into a rather bizarre problem regarding printing the page, and I'm hoping that someone could help me figure out what I'm doing wrong.

I've got three specific areas of the output page I'm supposed to have: Header block, general information block, detail block. Given that they're the more important ones, I worked on the general info and detail blocks first. And, if they're all that's present in the report, then it'll print fine.

However, when I include the header code [currently, only one sample out of three - I want to get this working first], it does some wonky stuff to apparent printouts in the Firefox Browser. (Appears to work correctly in IE, but we use Firefox for pretty much all browsers here.) I've been testing with a three page long (in the report) data sample .By 'wonky', I mean that the header block is the only thing that prints on the first page, nothing prints on the second page, and then the third page kicks in like there wasn't anything wrong, meaning it prints the real third page. Basically, I lose everything but the contents of the header block from the first two pages.

Here's the current code for the header block. Does anyone see anything with it that should be causing Firefox problems?

Code:
if ($form_type == 'NFHE')
{
  //Heading Block for form type NFHE
  echo "<TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1>$caption</FONT></B></CAPTION>\n";
  echo "<TBODY align=center>\n";
  echo "<TR><TH align=center><h1>*******************</h1></TH></TR>\n";
  echo "<TD align=center>Non-Food Handling Establishments QA Report</TD></TR>\n";
  echo "<TR><TD align=center><small>Churches, Offices, Department Stores, etc.</small></TD></TR>\n";
  echo "</TBODY></TABLE>\n";
}
 
you don't start the table row here
Code:
 echo "<TD align=center>Non-Food Handling Establishments QA Report</TD></TR>\n";
 
I thank you for pointing that out, and it has been changed in the code. However, I'm still having the same printing error - or at least, it still shows up that way in print preview. Given that it showed the error effect in print preview and when printed out last time, I'm assuming it would do the same this time, without actually printing it.

Again, though, I thank you for pointing that out to me. Any other suggestions?
 
are you sure that you've refreshed your cache since fixing the problem at the server?
check the html source code to make sure.
 
Yes. I am certain of it, and the page source for that section follows:
Code:
<TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION>
<TBODY align=center>
<TR><TH align=center><h1>*******************</h1></TH></TR>
<TR><TD align=center>Non-Food Handling Establishments QA Report</TD></TR>
<TR><TD align=center><small>Churches, Offices, Department Stores, etc.</small></TD></TR>
</TBODY></TABLE>

But I'm still getting the same problem. Where else should I start checking?
 
I would check what your code is actually outputting, seems to me your creating blank space when you generate your table. Can we see the code that generates the rest of your table.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
That was the entire table...at least that one. However, I'm beginning to think it's the one after that that's going crazy on me, since it's the one that partially disappears. It's a bit long (multiple ifs per table row), but I'll try for a sample.

Code:
echo "<TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1>$caption</FONT></B></CAPTION>\n";
echo "<TBODY ALIGN=left>\n";

if ($form_type == 'NFHE')
{
  //Results block for form type NFHE
  echo "<TR><TD colspan=2><B>Interior: Also includes break/kitchen areas</B></TD></TR>\n";
  echo "<TR><TH>Question</TH><TH>Response</TH><TH>Explanation</TH></TR>\n";
  [COLOR=green]$fieldval++;
  $count1 = substr_count($cust_sat, '1');
  if ($count1 < 1)
  {
    $count1 = 1;
  }
  echo "<TR valign=top><TD rowspan=$count1>1. Is the customer satisfied with all phases of the service and the technician?</TD>\n";
  if (strtoupper(substr($cust_sat, 0, 1)) == 'Y')
  {
    echo "<TD>Yes</TD><TD></TD></TR>\n";
  }
  if (strtoupper(substr($cust_sat, 0, 1)) == 'N')
  {
    echo "<TD rowspan=$count1>No</TD>\n";
    $x = 0;
    while ($x <= $count1)
    { 
      $y = $x+2;
      if (substr($cust_sat, $y, 1) == '1')
      {
        include "zMessage.php";
        echo "<TD colspan=2>$zMessage</TD></TR><TR>\n";
      }
      $x++;
    }
    echo "</TR>\n";      
  }
  if (strtoupper(substr($cust_sat, 0, 1)) == 'I')
  {
    echo "<TD>N/A</TD><TD></TD></TR>\n";
  }[/color]

...

}

echo "</TBODY></TABLE>\n";

Everything in green gets repeated for every question on the original form. $Fieldval marks which question is being looked at, and starts at zero. (So when getting to the first question, it's fieldval == 1.)

The file zMessage.php uses the contents of $fieldval and $y in a set of switch statements to determine a single value for the $zMessage variable - one of the specific possible answers to the original question.


I don't think I'm generating any blanks or extraneous output, though. It looks fine when viewed in the browser. The only problem is that part of it suddenly gets removed during the print/print preview by the browser in Firefox. This doesn't happen in Internet Explorer, only Firefox. However, we mostly use Firefox here for reporting, and at least one request I've had made seems to require a CSS component (I'm thinking CSS2) that IE doesn't seem to support.

Is there any way the code itself could interfere with the printout segment?
 
is this segment correct
Code:
while ($x <= $count1)
    { 
      $y = $x+2;
      if (substr($cust_sat, $y, 1) == '1')
      {
        include "zMessage.php";
        echo "<TD colspan=2>$zMessage</TD></TR><TR>\n";
      }
      $x++;
    }
you seem to be starting a row at the end of the echo.

but this is very difficult to debug like this. can you post the html that gives you the problem and we can point out where to look in the php.
 
Below is a complete copy of the source html for a run. All actual data has been blotted out, but there are no changes to the structure of the code. This has been verified to produce the same problem in the browser's print preview (haven't tried to actually print it yet) as the one with the data information intact. The lines in green are the code governing the portion which actually vanishes when attempting to print. Some of the information controlled by the code near the end of the green segment occasionally appears, but the only constant factor there seems to be that anything on the last printed page will, in fact, show up.

Code:
<link rel="stylesheet" type="text/css" media="print" href="cancelheader.css"/><TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION>
<TBODY align=center>
<TR><TH align=center><h1>**********</h1></TH></TR>
<TR><TD align=center>Non-Food Handling Establishments QA Report</TD></TR>
<TR><TD align=center><small>Churches, Offices, Department Stores, etc.</small></TD></TR>
</TBODY></TABLE>
<br/><br/><TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION>
<TBODY ALIGN=left>
<TR>
<TD width=40%>QA Inspection Date: **********</TD>
<TD width=15%>District: **********</TD>
<TD>Technician: **********</TD>

<TD>Route: **********</TD>
</TR>
<TR>
<TD colspan=2>Name of Account: **********</TD>
<TD colspan=2>Contact: **********</TD>
</TR>
<TR>
<TD colspan=2>Service Address: **********</TD>
<TD>City: ********** </TD>
<TD>State: **********</TD>

</TR>

<TR>
<TD></TD>
<TD></TD>
<TD></TD>
<TD>Grade: **********</TD>
</TR>
</TBODY></TABLE>
[COLOR=green]<TABLE BORDER=0 RULES=0 GROUPS WIDTH=100%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION>
<TBODY ALIGN=left>
<TR><TD colspan=2><B>Interior: Also includes break/kitchen areas</B></TD></TR>
<TR><TH>Question</TH><TH>Response</TH><TH>Explanation</TH></TR>

<TR valign=top><TD rowspan=5>1. ****************************************************************************</TD>

<TD rowspan=5>No</TD>


<TD colspan=2>***********************************</TD></TR><TR>


<TD colspan=2>****************</TD></TR><TR>


<TD colspan=2>**********</TD></TR><TR>


<TD colspan=2>******************************************</TD></TR><TR>


<TD colspan=2>********************************************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=3>2. ****************************************************</TD>
<TD rowspan=3>No</TD>


<TD colspan=2>*******************************</TD></TR><TR>


<TD colspan=2>********************************</TD></TR><TR>


<TD colspan=2>*********************************************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=9>3. ******************</TD>
<TD rowspan=9>No</TD>


<TD colspan=2>******************</TD></TR><TR>


<TD colspan=2>************************</TD></TR><TR>


<TD colspan=2>*********</TD></TR><TR>


<TD colspan=2>*************</TD></TR><TR>


<TD colspan=2>***********</TD></TR><TR>

<TD colspan=2>***********</TD></TR><TR>

<TD colspan=2>***********</TD></TR><TR>


<TD colspan=2>**********</TD></TR><TR>


<TD colspan=2>*******************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=3>4. ******************</TD>

<TD rowspan=3>No</TD>

<TD colspan=2>****</TD></TR><TR>


<TD colspan=2>*********</TD></TR><TR>


<TD colspan=2>***********</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=2>5. *****************************************************************</TD>
<TD rowspan=2>No</TD>

<TD colspan=2>*****************************</TD></TR><TR>


<TD colspan=2>*********************************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=10>6. *************************************************</TD>
<TD rowspan=10>No</TD>


<TD colspan=2>***********</TD></TR><TR>

<TD colspan=2>********************</TD></TR><TR>


<TD colspan=2>***********************************</TD></TR><TR>


<TD colspan=2>**************************************</TD></TR><TR>


<TD colspan=2>************************************************</TD></TR><TR>


<TD colspan=2>***************</TD></TR><TR>


<TD colspan=2>**********************</TD></TR><TR>


<TD colspan=2>******************</TD></TR><TR>


<TD colspan=2>****************************</TD></TR><TR>


<TD colspan=2>***********************************</TD></TR><TR>

</TR>
<TR valign=top><TD rowspan=7>7. ************************************************************************</TD>
<TD rowspan=7>No</TD>


<TD colspan=2>***************************</TD></TR><TR>


<TD colspan=2>**************************</TD></TR><TR>


<TD colspan=2>***********************************</TD></TR><TR>


<TD colspan=2>***********************************************</TD></TR><TR>


<TD colspan=2>********************************</TD></TR><TR>


<TD colspan=2>**************</TD></TR><TR>


<TD colspan=2>*******************</TD></TR><TR>
</TR>

<TR valign=top><TD rowspan=2>8. *************************************</TD>
<TD rowspan=2>No</TD>


<TD colspan=2>*************</TD></TR><TR>


<TD colspan=2>***************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=2>9. *******************************************************************</TD>
<TD rowspan=2>No</TD>


<TD colspan=2>****************</TD></TR><TR>


<TD colspan=2>********************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=3>10. *******************************************************************************</TD>
<TD rowspan=3>No</TD>


<TD colspan=2>*********</TD></TR><TR>


<TD colspan=2>*******************************</TD></TR><TR>


<TD colspan=2>***********************</TD></TR><TR>
</TR>
<TR><TD><BR/></TD></TR><TR><TD colspan=2><B>Exterior:</B></TD></TR>
<TR><TH>Question</TH><TH>Response</TH><TH>Explanation</TH></TR>
<TR valign=top><TD rowspan=3>1. ***************************************</TD>

<TD rowspan=3>No</TD>


<TD colspan=2>******************</TD></TR><TR>


<TD colspan=2>************************</TD></TR><TR>


<TD colspan=2>******************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=2>2. *******************************************</TD>

<TD rowspan=2>No</TD>


<TD colspan=2>*******************</TD></TR><TR>


<TD colspan=2>***************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=3>3. **********************************</TD>
<TD rowspan=3>No</TD>

<TD colspan=2>*************************************************************</TD></TR><TR>


<TD colspan=2>***************************************************</TD></TR><TR>


<TD colspan=2>***************************************************</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=3>4. *******************</TD>
<TD rowspan=3>No</TD>

<TD colspan=2>****</TD></TR><TR>


<TD colspan=2>*********</TD></TR><TR>


<TD colspan=2>***********</TD></TR><TR>
</TR>
<TR valign=top><TD rowspan=5>5. ******************?</TD>
<TD rowspan=5>No</TD>

<TD colspan=2>*******************</TD></TR><TR>


<TD colspan=2>*********</TD></TR><TR>


<TD colspan=2>************************</TD></TR><TR>


<TD colspan=2>**************</TD></TR><TR>


<TD colspan=2>*******</TD></TR><TR>

</TR>
<TR valign=top><TD rowspan=13>6. ****************************************</TD>
<TD rowspan=13>No</TD>


<TD colspan=2>**********************</TD></TR><TR>


<TD colspan=2>*******************************</TD></TR><TR>

<TD colspan=2>********************************************</TD></TR><TR>


<TD colspan=2>****************************************</TD></TR><TR>


<TD colspan=2>**************************************************************</TD></TR><TR>


<TD colspan=2>****************************</TD></TR><TR>


<TD colspan=2>**********************</TD></TR><TR>

<TD colspan=2>****************</TD></TR><TR>


<TD colspan=2>******************************</TD></TR><TR>


<TD colspan=2>"*****************************</TD></TR><TR>


<TD colspan=2>*************************</TD></TR><TR>


<TD colspan=2>*****************************</TD></TR><TR>


<TD colspan=2>***********************************************</TD></TR><TR>
</TR>
</TBODY></TABLE>[/color]
 
You seem to have varying amounts of cells in your rows, and then you have empty rows also.

However I copied your code and pasted it into a new file, and it does not exhibit any problems. The preview has the header and the rest of information as it should.

So the next culprit might be your CSS file. can you tell us what is in it?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
could the css file called cancelheader.css be anything to do with your issue? it's set for print media only.

your html does not validate either. always good to make sure that this is fixed before attempting other debugging.

in addition, as an aide to debugging, consider rearranging your php code so that the resulting html is nicely formatted and indented. i'll post back with what i mean.


 
this is what i meant
Code:
echo <<<HTML
<table border="0" rules="0" width="100%">
	<caption><b><font size="+1">$caption</font></b></caption>
	<tbody align="left">

HTML;

if ($form_type == 'NFHE'){
  //Results block for form type NFHE
  echo <<<HTML
 		<tr>
			<td colspan="2">
				<b>Interior: Also includes break/kitchen areas</b>
			</td>
		</tr>
		<tr>
			<th>
				Questions
			</th>
			<th>
				Responses
			</th>
			<th>
				Explanations
			</th>
		</tr>

HTML;

being space and indent conscious like this makes it _much_ easier to debug. even better, however, would be to avoid using tables.
 
@Vacunita:
The css file in question consists of a single line designed to force a pagebreak anytime it hits a paragraph tag.

Code:
p { page-break-before: always;}

I've used this in the past to create breaks at appropriate spots, so that I don't have some group of items with half of it on one page and half on another; it didn't seem to be working on a test run this time around, so I asked in the HTML/CSS forum here if anyone had any suggestions as to why. The response I got suggested adding the 'media="print"' bit of code to the css link. It didn't work out, but given that the only way I could get a full print version up was with Internet Explorer, I'm beginning to suspect that the problem is that the copy of IE I have here doesn't support that particular command, which I believe is part of the CSS2 listing.

I went through and removed the code segments that generated the paragraph tags I was using as my pagebreak markers from the original php as I was somewhat afraid they might have something to do with the problems I was having. (They don't: The problem continued after this.) Assuming I ever figure out what I'm doing wrong with the printing side, they'll be put back in.
 
Actually I was the one that suggested the media=print. However I was not aware you were using tables.

Where would you be putting paragraph tags if all you have is a big long table. You obviously cannot break apart a table with paragraph tags.

If I put in a paragraph tag mid way through your table, then I get the problem you describe in FF.

IE7 seems to ignore that all together.

So the problem ends up being the <p> tags. In the code you posted there are no <p> tags, but you may have missed 1 around in your real code somewhere.










----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Problem seemingly solved.

The original code that threw the problem didn't include the paragraph tags*. However, it did include tables of unusually large size.

Apparently, the table was so large that Firefox didn't want to print it out. Placing 'table breaks' in the code appears to have solved everything.

*Original usage of paragraph tags was as follows:
Code:
//Appears at every <TR> statement, since those
//are where the actual 'new lines' occur.

if ($lineCount > $n)  //$n = max number of lines on page
{
  echo "  </TBODY>\n";
  echo "</TABLE>\n";
  echo "<p/>\n";
  echo "<TABLE>\n";
  echo "  <TBODY>\n";
  $lineCount = 1;
}
echo "    <TR>\n";
Since it broke the table as part of the code, the p tag was picked up normally. With this in place, the program prints out cleanly and naturally.

Thanks for the assistance, everyone. I appreciate it.
 
Glad you sorted it out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top