【发布时间】:2014-04-15 08:56:06
【问题描述】:
我被这些困住了。
this is my array:
$tabel3 = array (
array (
"progdas" => "Java", "sks" => "3", "prior" => "2"
),
array (
"progdas" => "C#", "sks" => "6", "prior" => "1"
),
array (
"mat" => "Dasar", "sks" => "3", "prior" => "1"
),
array (
"mat" => "Lanjut", "sks" => "3", "prior" => "3"
),
);
这是在表格中显示它的代码:
<?php
echo "Tabel 3<br />";
echo "<table width='auto' border='1'>";
//header
echo "
<table width='auto' border='1' >
<tr>
<th colspan='2' scope='col'>Mata Kuliah</th>
<th width='auto' scope='col'>Jumlah SKS</th>
<th width='auto' scope='col'>Prioritas</th>
</tr>
";
foreach ($tabel3 as $rows => $row)
{
//isi
echo "<tr>";
if ($cell == "progdas") {
echo "<th width='auto' rowspan='2' scope='row'>Pemrograman Dasar</th>";
foreach ($row as $col => $cell)
{
echo "<td>" . $cell. "</td>";
}
}
else {
echo "<th width='auto' rowspan='2' scope='row'>Matematika</th>";
foreach ($row as $col => $cell)
{
echo "<td>" . $cell. "</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>
我希望表格看起来像这样:
-----------------------------------------------------
Mata Kuliah | Jumlah SKS | Prioritas |
-----------------------------------------------------
Pemrograman Dasar|_Java___|____________|____________|
_________________|_C#_____|____________|____________|
Matematika |_Dasar__|____________|____________|
_________________|_Lanjut_|____________|____________|
有人知道如何跨行数据“Pemrograman Dasar”和“Matematika”吗?我在这段代码中得到了不好的结果。
【问题讨论】:
标签: php html arrays html-table