I exported data from a PHP page to a Word document but the header is not available in all pages.
Header is present in the first page but not in the other pages of the Word document.
Here is my code,
function changeDetails()
{
$bType = $this->input->post('textvalue');
if ($bType == "word")
{
$this->load->library('table');
$data['countrytoword'] = $this->AddEditmodel1->export();
$this->table->set_heading('Name','Country','State','Town');
$out = $this->table->generate($data['countrytoword']);
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-disposition: attachment; filename=$cur_date.doc");
echo '<br><br>';
echo '<strong>CountryList</strong><br><br>';
print_r($out);
}
}
<? if(isset($countrytoword)) { ?>
<table align="center" border="0">
<tr>
<td>Name</td>
<td>Country</td>
<td>State</td>
<td>Town</td>
</tr>
<? foreach($countrytoword as $dsasffd) { ?>
<tr>
<td><?= $dsasffd['dbName'] ?></td>
<td><?= $dsasffd['dbCountry']; ?></td>
<td><?= $dsasffd['dbState']; ?></td>
<td><?= $dsasffd['dbTown']; ?></td>
<? } } ?>
</tr>
</table>
If you mark the header row(s) with a <thead> element you should get what you want. So this code becomes