【问题标题】:Read data from multiple rows PHP MySQL从多行 PHP MySQL 中读取数据
【发布时间】:2010-10-30 21:55:19
【问题描述】:

我有一个数据库来跟踪客户的服务。但需要能够找到所有服务(在不同的行上)并将它们显示在 HTML 表格中。

Service     Company         Status
-------------------------------------
Service 1   Company 1       Complete
Service 2   Company 2       Pending
Service 3   Company 1       Complete

我需要提取公司 1 的每个条目的服务和状态,并将其显示在 HTML 表格中。这是怎么做到的?

【问题讨论】:

    标签: php mysql html database extract


    【解决方案1】:

    代码:

    <table>
    <thead>
      <tr>
        <th>Service</th>
        <th>Status</th>
      </tr>
    </thead>
    <?php $result = mysql_query("SELECT Service, Status FROM services WHERE Company='Company 1'");
      while ($row = mysql_fetch_array($result)) {
              //  ^ must be a single '=' !!!!
          echo '<tr><td>' . $row["Service"] . '</td>';
          echo '<td>' . $row["Status"] . '</td></tr>';
      } ?>
    </table>
    

    【讨论】:

    • @Query 好点;当我写答案时,我完全是个菜鸟。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多