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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing large tables with specific headers on each page 1

Status
Not open for further replies.

erebus

Programmer
Aug 1, 2003
6
US
Hi, I am working on enhancing a web page that is table based. My hopes are to make a printable page that attaches the first few rows of the table on the top of each page. Since the information for the table is stored in a database and each table will end up different lengths and what not, is there any way to ensure that the header goes on each printed page? If that makes any since at all...

Thanks
 
Sure you can do that. If you can code the HTML to do it, you can code the PHP to do it dynamically... I suppose the trick is to know how many rows fit on a page?

Basically you'll just want to do something like...
Code:
$rows_per_page=20;

$current_row=0;
while ($newrow = howeveryougetyourrows) {
  if ($current_row = 0) {
    print_headers();
  }
  print_row();
  $current_row++;
  if ($current_row = $rows_per_page) {
    $current_row=0;
  }
}

That's an overly verbose approach, but I think it illustrates.

-Rob
 
That seems as if it could work, but I do not know if I could make it work for me. The problem with it is my table can have basically anywhere from 5 (worst case)-16(best case) rows on a page and it will probably be closer to 16 per page but there is always the chance of that not being true...It is really only one column that is causing a problem. I have included the part of the code that I see as the problem. For each row you can have up to 9 lines, if the person says they used each of the selections then it will have 9 separate lines (the table is wide also, so they do each have to be on an individual line) or if they selected none of the options they will only see a '-'. Dose that make since?? Thanks!

Code:
echo &quot;  <td rowspan=\&quot;2\&quot; align=\&quot;left\&quot;>&quot;;

if ($odatasrc == 000000000) { echo &quot;<center>-</center>&quot;; }//set up the display of the other data sources
if ($AMSU == 1) { echo &quot;AMSU<br>&quot;; }
if ($TRMM == 1) { echo &quot;TRMM<br>&quot;; }
if ($SSMI == 1) { echo &quot;SSMI<br>&quot;; }
if ($GOES == 1) { echo &quot;GOES Ch. 2<br>&quot;; }
if ($SCAT == 1) { echo &quot;SCAT<br>&quot;; }
if ($AODT == 1) { echo &quot;AODT<br>&quot;; }
if ($TIE  == 1) { echo &quot;TIE<br>&quot;; }
if ($CIRA == 1) { echo &quot;CIRA<br>&quot;; }
if ($OTHR == 1) { echo &quot;OTHER&quot;; }

echo &quot;   </td>
 
Sure, just means you need to expand the code a little... the idea still stands, except now a row isn't a table row, but rather a line....

so the outline now is...

Code:
$rows_per_page=20;

$current_row=0;
while ($newrow = howeveryougetyourrows) {
  if ($current_row = 0) {
    print_headers();
  }
  if ($odatasrc == 000000000) { echo &quot;<center>-</center>&quot;;   
  }//set up the display of the other data sources
  if ($AMSU == 1) { echo &quot;AMSU<br>&quot;; $current_row++;}
  if ($TRMM == 1) { echo &quot;TRMM<br>&quot;; $current_row++;}
  if ($SSMI == 1) { echo &quot;SSMI<br>&quot;; $current_row++;}
  if ($GOES == 1) { echo &quot;GOES Ch. 2<br>&quot;; $current_row++;}
  if ($SCAT == 1) { echo &quot;SCAT<br>&quot;; $current_row++;}
  if ($AODT == 1) { echo &quot;AODT<br>&quot;; $current_row++;}
  if ($TIE  == 1) { echo &quot;TIE<br>&quot;; $current_row++;}
  if ($CIRA == 1) { echo &quot;CIRA<br>&quot;; $current_row++;}
  if ($OTHR == 1) { echo &quot;OTHER&quot;; $current_row++;}
  
  if ($current_row >= $rows_per_page) {
    $current_row=0;
  }
}

If you go with that idea directly you'll need to build in a buffer such that a row doesn't overflow the bottom of the page. My suggestion there would rather than echoing, I'd write to a buffer such that I can read the number of lines in the new row before I write it to the page. Does that make sense?

-Rob
 
What you are saying is what i was generally thinking. I do not however know anything about doing the buffer thing. Will that cover my problem with the number of rows for the page?

Thanks!
 
sure... so right now you echo everytime you want something printed right? Well instead do this...

Code:
$buffer = &quot;&quot;;
if (true) { $buffer .= &quot;some text&quot;; $lines++;}
if (true2) { $buffer .= &quot;some more text; $lines++;}

and so on...
now everytime you leave that brick of code, you have a variable $buffer which contains what you want to print, and you know how many lines.  So now you can add that number of lines to another variable which is counting the number of lines printed to the page.  If that sum is greater than the total number of lines available to you on that page, you need to print the proper number of blank lines.  Then reprint your headers, reset your line count, and print your new row.

-Rob
 
Ahhhhh! I see what you are saying now. I do think that I can now successfully create my page. Thanks a bunch!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top