日期:2014-05-17 浏览次数:20512 次
<?php mysql_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>';