【问题标题】:PHP Table row numberingPHP 表格行编号
【发布时间】: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>

【问题讨论】:

  • 这里还有一个解析错误,&lt;/th&gt;”
  • 你知道你可以用 CSS 做行号吗?我只是自己学的,虽然它的可能并不让我感到惊讶。不过非常简洁,请查看:stackoverflow.com/questions/17012421/auto-number-table-rows(我并不是说您必须在这里使用它。我只是觉得它很有趣且相关。)
  • @Don'tPanic 想想看,我记得我在很多个月前正在做一些类似的事情。我称那部分为“我的好日子”。
  • 我只会使用 $files 数组键 (+1)
  • @IdontDownVote 我同意,这是有道理的,假设索引是数字/顺序的。

标签: php html-table row


【解决方案1】:

只需添加一个从 1 a.g. 开始的计数器。 $计数器=1; 打印计数器而不是 'Yay' 并在 foreach 循环中递增:$counter++;

【讨论】:

    猜你喜欢
    • 2013-06-05
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 2014-11-24
    • 2017-07-22
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多