【发布时间】:2019-03-20 09:20:27
【问题描述】:
下面的代码生成一个表格,如附图所示。我需要编辑代码,以便“#”列显示行号(从第 1 行开始)而不是“Yay!”
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Yup'ik</th>
<th scope="col">English</th>
<th scope="col">Audio</th>
</tr>
</thead>
<tbody>
<?php
#cycle through rows
foreach ($files as $file) {
print("<tr>");
print("<th scope='row'>Yay!</th>”);
#cycle through columns
print("<td>$file[0]</td>");
print("<td>$file[1]</td>");
print("<td><a href='audio/$file[2]'>$file[2]</a></td>");
print("</tr>");
}
?>
</tbody>
</table>
【问题讨论】:
-
这里还有一个解析错误,
</th>” -
你知道你可以用 CSS 做行号吗?我只是自己学的,虽然它的可能并不让我感到惊讶。不过非常简洁,请查看:stackoverflow.com/questions/17012421/auto-number-table-rows(我并不是说您必须在这里使用它。我只是觉得它很有趣且相关。)
-
@Don'tPanic 想想看,我记得我在很多个月前正在做一些类似的事情。我称那部分为“我的好日子”。
-
我只会使用
$files数组键 (+1) -
@IdontDownVote 我同意,这是有道理的,假设索引是数字/顺序的。
标签: php html-table row