469,887 Members | 1,334 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,887 developers. It's quick & easy.

use css to prevent tables spilling over page

170 100+
Hi

I have some tables generated from php code where there's a bunch of tables on a page. Each table could be a different height depending on user input. And there could be any number of tables.

I want to stop a table splitting into two and putting the last half on the next page when it's printed. Is there a way to do this using css?

I was thinking something like

*get the print area available somehow
* work out each table's table height
* keep adding the table heights until the total exceeds the available print height available
* tell it to print all tables on that page except the last one
* repeat the above for subsequent pages

I don't know if any of this is possible, or even if there's a much easier way.

Can anyone help this css newbie? In case it helps, the table-generating code is below

Expand|Select|Wrap|Line Numbers
  1. $i=0;
  2. while ($i < $num) 
  3.     {
  4.     $entry=mysql_result($result,$i,"entry");
  5.     $date=mysql_result($result,$i,"date");
  6.     $comps=mysql_result($result,$i,"comps");
  7.     $workplace=mysql_result($result,$i,"workplace");
  8.     $id=mysql_result($result,$i,"id");
  9.     $c=explode(',',$comps);
  10.     $count=count($c);
  11.  
  12.     echo "<br><table width=600><tr><td><b>Written on ".$date." &nbsp;  [Workplace: ".ucfirst($workplace)."]</b><br><ul>";
  13.  
  14.  
  15.     for($k=0; $k<mysql_num_fields($resultinfo); $k++)
  16.         {
  17.         $fieldname = mysql_fetch_field($resultinfo, $k);
  18.         $var=$fieldname->name;
  19.  
  20.         foreach($c as $values)
  21.             {
  22.             if(mysql_result($resultinfo,0,$var)==$values && $values!="")
  23.                 {
  24.                 echo "<li>".strtoupper($values)." (".mysql_result($resultinfo,0,str_replace('short','name',$var)).")</li>";
  25.                 }
  26.             }
  27.         }
  28.  
  29. echo "</ul>".nl2br($entry)."</td></tr></table>";
  30.  
  31.     $i++;
  32.     }
  33.  
May 9 '07 #1
0 1119

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Alpenvrouwtje | last post: by
3 posts views Thread by Philip | last post: by
59 posts views Thread by phil-news-nospam | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.