问题未解决,接着提问!关于查询结果特殊显示的问题!
原帖:http://topic.csdn.net/u/20120214/16/171276bf-16a7-45a3-8224-fea338db7ee0.html?1686623126
这个帖子不能再回复了,另开一贴:
数据库结构、字段如下图:
要想达到这样的显示效果:
论坛上 jordan102 朋友帮忙写了个查询过程,PHP文件代码如下:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpmysql_connect('127.0.0.1','root','');mysql_select_db('jiagedata');$result=mysql_query("select year(add_date) as y,group_concat(yc_jiage) as str from yc_jiage group by year(add_date);") or die(mysql_error()); echo '<table>';while($row = mysql_fetch_assoc($result)){ echo '<tr>'; echo "<td>$row[y]</td>"; foreach(explode(',',$row['str']) as $v); echo "<td>$v</td>"; echo "<tr>";} echo "</table>";?>
while($row=mysql_fetch_assoc($result)){ $arr[$row[y]]=$row; } foreach($arr as $k=>$v){ $s_arr=explode(',',$v[str]);$n_arr=explode(',',$v[ss]); foreach($n_arr as $k1=>$n) $tmp[$k][$n]=$s_arr[$k1]; } echo '<table width="800" algn="center" cellspacing=0>'; echo "<tr>"; echo "<td>年月</td>"; for($i=1;$i<=12;$i ) echo "<td>{$i}月</td>"; echo "</tr>"; foreach($tmp as $k2=>$v){ echo "<tr>"; echo '<td>'.$k2.'</td>'; for($i=1;$i<=12;$i ){ echo "<td>$v[$i]</td>"; } echo '</tr>'; } echo '</table>';<div class="clear"></div>