2010-10-30 45 views
0

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

从多行读取数据PHP MySQL

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

我需要提取该服务和状态用于公司1的每个条目,并以HTML表格显示它。这是如何完成的?

回答

0

代码:

<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

为什么不mysqli的? – Query 2012-12-01 22:41:07

+0

@Query好点;当我写答案的时候,我总是小白。 – 2012-12-02 00:43:16