I'm trying to use PEAR::HTML_Table package to generate a table from multi-dimensional array, $data.
This is a dump of $data:
Array
(
[0] => Array
(
[0] => Office
[1] => Canvasser
[2] => Fundraising Hrs
[3] => PAC/Hr no PFU
[4] => PAC $ no PFU
)
[1] => Array
(
[0] => TBS1
[1] => Vatcher, Georgia
[2] => 29
[3] => 8.295
[4] => 481
)
)
EDIT: The first array is the row of my THEAD tags and any additional arrays will be rows in the TBODY tags.
And this is my code:
$data = $worksheet->toArray('', true, false, false); // PHPExcel
// build table
$table = new HTML_Table(array('class' => 'dt'), 0, true);
$thead =& $table->getHeader();
$tbody =& $table->getBody();
// loop through rows
for ($r = 0, $lr = count($data); $r < $lr; $r++) {
// loop through columns
for ($c = 0, $lc = count($data[$r]); $c < $lc; $c++) {
if ($r == 0) {
$thead->setCellContents($r, $c, $data[$r][$c]);
} else {
$tbody->setCellContents($r, $c, $data[$r][$c]);
}
}
}
// output html
echo $table->toHtml();
When it outputs the HTML, it returns a table with an extra row having blank cells in the TBODY tags. I cannot seem to figure out why it is doing that. It is important for me to get the right output because I am sending this output back to a JavaScript file for further processing.
How can I fix this?