【问题标题】:HTML table <td> results all returning on one row [duplicate]HTML表<td>结果全部返回一行[重复]
【发布时间】:2020-09-29 13:26:53
【问题描述】:

我目前正在从 Oracle 表中循环 SQL 结果。表中的所有行都返回正常,但是它们都停留在元素内,而不是像下面这样的新行

这是我当前的表...

   <div id="smtTable" class="targetDiv">
     <table width="40%" style="margin: 0 auto; border:1px solid;text-align:center; width: auto;" class="table table-sm table-dark">
         <tr>
           <th scope="col">Area</th>
           <th scope="col">Week 18</th>
           <th scope="col">Week 19</th>
           <th scope="col">Week 20</th>
           <th scope="col">Week 21</th>
           <th scope="col">Week 22</th>
         </tr>
<?php
 while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
     foreach ($row as $item) {
         echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
     }
 }
 ?>

【问题讨论】:

  • 您需要为每行数据添加行标签。只需将&lt;tr&gt;(和结束标签)添加到while 循环中。
  • 新行不需要 元素吗?

标签: php html


【解决方案1】:

您需要关闭table 并添加tr 作为行的标记:

<?php
 while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {

echo '<tr>';
      foreach ($row as $item) {
     echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
      }
echo '</tr>';
 }
echo '</table>';
 ?>

【讨论】:

  • meta.stackoverflow.com/q/397526/2943403 请关闭可关闭的问题。
  • 您选择的答案不能解释当前问题。有时新手需要知道他的情况到底出了什么问题
  • 或者他们只需要显示预先存在的答案所在的位置,而不会在 Stackoverflow 上生成不必要的内容。
猜你喜欢
  • 1970-01-01
  • 2018-07-17
  • 2013-10-10
  • 2012-03-27
  • 2016-09-10
  • 1970-01-01
  • 2018-08-13
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多