2017-08-24 44 views
0

根據用戶選擇的選項,可以有不同的數字。因此,我創建了一個函數,它將從兩個數組中生成一個表格。第一個是列標題的名稱,第二個是實際的數據。這是我的函數:從數組中加倍回顯表格

function terminalTables ($numCol, $tableName, $data, $colName, $aircraft, $servicePack){ 

echo '<h3> Tail: '.$aircraft.'<br> Service pack: '.$servicePack.'</h3>'; 
echo '<table id="'.$tableName.'" cellpadding="2" cellspacing="2" style="text-align:center;" class="db-table db-table dTableWidth dataTable no-footer">'; 
echo '<thead>'; 
foreach ($colName as $col){ 
    echo '<th scope="col" style="white-space:nowrap">column:'.$col.'<th>'; 
} 
/*for ($ii = 0; $colName[$ii] != NULL; $ii++){ 
    echo "<script>alert(\"column name: $colName[$ii]\");</script>"; 
    echo '<th scope="col" style="white-space:nowrap">'.$colName[$ii].'<th>'; 
}*/ 
echo '</thead>'; 
echo '<tbody>'; 
for ($iii = 0; $data[$iii] != NULL; $iii++){ 
    echo '<tr>'; 
    for ($j = 0; $j < $numCol; $j++){ 
     echo "<td style='white-space:nowrap; padding-left:1em; padding-right:1em;'>".$data[$iii][$j].'</td>'; 
    } 
    echo '</tr>'; 
} 
echo '</tbody>'; 
echo '</table>'; 
exit; } 

所有被正確顯示的數據,但是列數在THEAD被複制

當我們檢查的表頭元素,這就是我們得到:

<table id="datatable" class="db-table db-table dTableWidth dataTable no-footer" style="text-align:center;" cellspacing="2" cellpadding="2"> 
 
    <thead> 
 
    <tr> 
 
     <th scope="col" style="white-space:nowrap">column:Event Time</th> 
 
     <th></th> 
 
     <th scope="col" style="white-space:nowrap">column:Event Type</th> 
 
     <th></th> 
 
     <th scope="col" style="white-space:nowrap">column:Rx Bytes Since power on (KB)</th> 
 
     <th></th> 
 
     <th scope="col" style="white-space:nowrap">column:Tx Bytes Since power on (KB)</th> 
 
     <th></th> 
 
     <th scope="col" style="white-space:nowrap">column:Link Start Time</th> 
 
     <th></th> 
 
    </tr> 
 
    </thead>

請注意,在每個實際列前,我們有列:命名。我們共有5個實際的專欄和5個。正因爲如此,我的桌子完全被推到了一邊。

picture of the table with yellow highlight on colulmn: and the empty columns

我一直在試圖調試這太長時間,現在我的頭很痛。我做錯了什麼?非常感謝你。

+0

''標籤需要包裹在'單曲就像''​​就做 – bassxzero

+0

'$數據[$ III] = NULL;'也許應該是'$ iii bassxzero

+0

這是真的我忘了但我仍然有額外的列 –

回答

0

找出我的錯誤,我很生氣。這是我原本的代碼:

echo '<th scope="col" id="terminalTables">'.$col.'<th>'; 

請注意,在行末,我沒有一個but。是的,我是個白癡。 它應該一直是這樣的:!

echo '<th scope="col" id="terminalTables">'.$col.'</th>';