首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正确地将php格式化为html表

正确地将php格式化为html表
EN

Stack Overflow用户
提问于 2015-08-11 17:13:07
回答 1查看 87关注 0票数 0

我有一个php数组,它包含来自我的数据库$name[] = $row['name']的信息。还有大约3行容器emailagescreen-resolution

我正试着把它整齐地塞进一张桌子上,看上去像:

name----------email----------age----------screen-res

name1---------email1--------age1---------res1

name2---------email2--------age2---------res2

然而,我目前的情况如下:

name----------email----------age----------screen-res

name1---------name2----------name3------name4---------name5------name6-------name7------name8

email1---------email2----------email3------email---------email5------email6-------email7

我的密码

代码语言:javascript
复制
<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Age</th>
    <th>Screen-Res</th>
  </tr>
  <?php
    echo "<tr>";
    foreach ($name as $nameVal) {
        echo "<td>$nameVal</td>";
    }
    echo "</tr>";

    echo "<tr>";
    foreach ($email as $emailVal) {
        echo "<td>$emailVal</td>";
    }
    echo "</tr>";

    echo "<tr>";
    foreach ($age as $ageVal) {
        echo "<td>$ageVal</td>";
    }
    echo "</tr>";

    echo "<tr>";
    foreach ($screen-res as $screen-resVal) {
        echo "<td>$screen-resVal</td>";
    }
    echo "</tr>";
  ?>
</table>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-11 17:18:24

您的表格式不正确。你的桌子看起来像这样。好的是,对于所有的数据,只需要一个数组。

代码语言:javascript
复制
<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Age</th>
    <th>Screen-Res</th>
  </tr>
  <?php

    foreach ($rows as $row) {
        echo "<tr>";
        echo "<td>".$row['nameVal']."</td>";

        echo "<td>".$row['emailVal']."</td>";

        echo "<td>".$row['ageVal']."</td>";

        echo "<td>".$row['screen-resVal']."</td>";
            echo "</tr>";
    }

  ?>
</table>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31947981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档