开发者

Read data from multiple rows PHP MySQL

开发者 https://www.devze.com 2023-01-22 12:51 出处:网络
I have a database to keep track of the services clients have. But need to be able to find all the services (on different rows) and display them in an HTML table.

I have a database to keep track of the services clients have. But need to be able to find all the services (on different rows) and display them in an HTML table.

i.e.

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

I need to extract the service and status for each entry 开发者_Python百科for Company 1 and display it in an HTML table. How is this done?


Code:

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消