请问:查询DB后相同类型的记录合并为一行显示且可展开

WBOY
Release: 2016-06-13 11:48:31
Original
828 people have browsed it

请教:查询DB后相同类型的记录合并为一行显示且可展开。
数据在DB中存储如上图,现在要在页面如下图显示,即:相同编码的记录显示为一行,且将“费用”列做加法;点击加号可展开为实际记录。

------解决方案--------------------

<br />$res =mysql_query(select 工程,编码,sum(费用) from table group by 编码)<br />foreach($res as $k=>$v){<br />   $res[$k]['child']  =  mysql_query(select 工程,编码,费用 from table where 编码=$v['编码']);<br />}<br />echo '<table><tr><td>工程</td><td>编码</td><td>费用</td></tr>';<br />foreach($res as $v){<br />   echo '<tr><td>$v['工程']</td><td>$v['编码']</td><td>$v['费用']</td></tr>';<br />   foreach($v['child'] as $vv){<br />      echo '<tr   style="max-width:90%"><td>$vv['工程']</td><td>$vv['编码']</td><td>$vv['费用']</td></tr>';<br />   }<br />}<br />echo '</table>';<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!