dongzhaobai5982 2008-10-20 15:41
浏览 25
已采纳

如何使用PHP在行跨中显示mysql数据?

I have data from MySQL showing all organisations a customer got, with all details of employess in each organisation. I want to list each organisation name only once i.e. in a single cell ( row span) and all employees in that organisation against this name like:

Org1     Emp1 Name, Emp1 Phone, Emp1 Address
         Emp2 Name, Emp2 Phone, Emp2 Address


Org2     Emp1 Name, Emp1 Phone, Emp1 Address
         Emp2 Name, Emp2 Phone, Emp2 Address

How do I display this data because the number of employess for each organisation is not known in advanced, so I do'nt about setting value of rowspan. Similarly how do I start a row for other organisation? Do I have to write two queries?

Many Thanks.

  • 写回答

7条回答 默认 最新

  • dongyongyu0789 2008-10-20 15:50
    关注

    Classic.

    Workaround: only display the name if different than the previous one. You can even not bother about the rowspan (you keep an empty cell).

    $currentOrg = '';
    while ($row = mysql_fetch_object($query)) {
       if ($row->org != $currentOrg) {
          echo "$row->org".
       }
       $currentorg = $row->org;
    }
    

    Not the most beautiful but so simple.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?