我正在使用此代码生成一个表,随后将对其进行修改以将数据上载到mysql数据库。
<?php
$start_loc_number= 1 ;
$start_loc_alpha= 'A' ;
$end_loc_number= 10 ;
$end_loc_alpha= 'J' ;
$out = '';
$out .= '<table border = 1 bordercolor="#FF0000">';
for($tr='A';$tr<=$end_loc_alpha;$tr++)
{ $out .= "<tr>";
for($td=1;$td<=$end_loc_number;$td++)
{ $out .= '<td BGCOLOR="#99CCFF">'.$tr.$td.'</td>
<td id="sampleID" contenteditable="true"> sampleID</td>
<td id="volume" contenteditable="true"> volume</td>' ;
}
$out .= "</tr>";
}
$out .= "</table>";
echo $out;
?>
目前,该表在3个列单元格中每次迭代生成3个单元格,
| coordinates | sample ID | volume |
我的问题涉及如何更改php代码以生成一个表格,其中坐标单元格可以排列为sampleID上的行距,而单元格中的体积单元格位于2行,样本ID位于体积单元格
| | sample ID
| coordinates |------------
| | volume
答案 0 :(得分:1)
这对我有用
<table>
<tr>
<td rowspan="2">test</td>
<td>test1</td>
</tr>
<tr>
<td>test2</td>
</tr>
</table>
编辑:fiddle
答案 1 :(得分:1)
试试这个,
for($tr='A';$tr<=$end_loc_alpha;$tr++)
{ $out .= "<tr>";
for($td=1;$td<=$end_loc_number;$td++)
{ $out .= '<td BGCOLOR="#99CCFF">'.$tr.$td.'</td><td>
<table><tr style="border-bottom: 1px solid red">
<td id="sampleID" contenteditable="true"> sampleID</td></tr>
<tr> <td id="volume" contenteditable="true"> volume</td></tr></table></td>' ;
}
$out .= "</tr>";
}
答案 2 :(得分:1)
你可以在你的坐标TD上设置rowspan="2"
。
你真的不应该那样建立你的输出。 试试这种方法:
<?php
$content = array(
array(
'cords' => 1,
'samp' => "Bar",
'vol' => 13
),
array(
'cords' => 2,
'samp' => "Foo",
'vol' => 456
),
array(
'cords' => 3,
'samp' => "DJ",
'vol' => 34
)
);
?>
<table>
<tbody>
<? foreach($content as $key => $value) { ?>
<tr>
<th rowspan="2">Coordinates: <?= $value['cords'] ?></th>
<td>sample ID: <?= $value['samp'] ?></td>
</tr>
<tr>
<td>volume: <?= $value['vol'] ?></td>
</tr>
<? } ?>
</tbody>
</table>