title: Repeating Table Headers in HTML
body: <p>I have a large dataset from MySQL that I am displaying using PHP. If the user tries to print it, it has some 50 pages of data. </p>
  
  <p>The entire data is displayed using tables and simple PHP <code>echo-s</code> that display the data in the table fields.</p>
  
  <p>What I need is - when a user tries to print it OR export to PDF in Safari (Mac), the table headers should appear on all pages. How can this be done?</p>
  
  <p>Thanks</p>
  
  <p>Edit: I have enclosed the table headers under  but it doesnt work. It's a plain HTML page with no scripts that just displays data from database.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>echo "&lt;table border='1'&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;th colspan=13&gt;Item Info&lt;/th&gt;
  &lt;th colspan=4&gt;Lot Info&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;th bgcolor='#C8E3FF'&gt;S.No.&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Party Name&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Item No.&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Date&lt;/th&gt;
  
  &lt;th&gt;Flower&lt;/th&gt;
  
  &lt;th bgcolor='#C8E3FF'&gt;Lot No.&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Avg Wt.&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Total Weight&lt;/th&gt;
  &lt;th bgcolor='#C8E3FF'&gt;Detail Page&lt;/th&gt;
  &lt;/tr&gt;&lt;/thead&gt;&lt;tfoot&gt;&lt;/tfoot&gt;&lt;tbody&gt;";
  
      echo "&lt;tr&gt;";
      echo "&lt;td bgcolor='#C8E3FF' rowspan=".$itemCounter."&gt;".$sno."&lt;/td&gt;";
      echo "&lt;td bgcolor='#C8E3FF' rowspan=".$itemCounter."&gt;".$row['partyName']."&lt;/td&gt;";
  
      while($row2 = mysqli_fetch_array($itemquery))
      {
          $itemNo++;
          echo "&lt;td bgcolor='#C8E3FF'&gt;".$itemNo."&lt;/td&gt;";
          echo "&lt;td bgcolor='#C8E3FF'&gt;".$row2['date']."&lt;/td&gt;";
  
  
              //$flower = $flower + $row2['flower'];
              echo "&lt;td&gt;".$row2['flower']."&lt;/td&gt;";
  
  
  
          echo "&lt;td  bgcolor='#C8E3FF'&gt;".$row2['lotno']."&lt;/td&gt;";
          echo "&lt;td bgcolor='#C8E3FF'&gt;".$row2['avgwt']."&lt;/td&gt;";
          if ($row2['totalWeight'] == 0)
          {
              echo "&lt;td  bgcolor='#C8E3FF'&gt; &lt;/td&gt;";
          }
          else{
              $totalWt = $totalWt + $row2['totalWeight'];
              echo "&lt;td  bgcolor='#C8E3FF'&gt;".$row2['totalWeight']."&lt;/td&gt;";    
          }
  
          echo "&lt;td  bgcolor='#C8E3FF'&gt;".$row2['detailPage']."&lt;/td&gt;";
          echo "&lt;/tr&gt;";
      }
      echo "&lt;td bgcolor='#C8E3FF'&gt;&lt;b&gt;Total&lt;/b&gt;&lt;/td&gt;";
  
  
      echo "&lt;td&gt;&lt;b&gt;".$flower."&lt;/b&gt;&lt;/td&gt;";
  
  
  
          echo "&lt;td bgcolor='#C8E3FF'&gt;&lt;/td&gt;";
          echo "&lt;td bgcolor='#C8E3FF'&gt;&lt;/td&gt;";
  
              echo "&lt;td bgcolor='#C8E3FF'&gt;&lt;b&gt;".$totalWt."&lt;/b&gt;&lt;/td&gt;";  
  
          echo "&lt;td  bgcolor='#C8E3FF'&gt;&lt;/td&gt;";
          echo "&lt;/tr&gt;";
          echo "&lt;tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;/tr&gt;";
  
  }
  echo "&lt;/tbody&gt;&lt;/table&gt;";
  </code></pre>