php - HTML_Table returns an incorrect output -


i'm trying use pear::html_table package generate table multi-dimensional array, $data.

this 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: first array row of thead tags , additional arrays rows in tbody tags.

and 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 ($r = 0, $lr = count($data); $r < $lr; $r++) {     // loop through columns     ($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 outputs html, returns table row having blank cells in tbody tags. cannot seem figure out why doing that. important me right output because sending output javascript file further processing.

how can fix this?

you need reset counter row in tbody.

the first body cell gets coordinates (1,0), should have (0,0) - row position begins @ 0, not @ 1. implicit tell html_table add clear row before first row.

to fix it, use $r - 1 instead of $r in else block. , learn foreach().


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -