21,887
社区成员
发帖
与我相关
我的任务
分享
<?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>";
?>
<?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());
while($row=mysql_fetch_assoc($result)){
$arr[$row['y']]=$row;
}
foreach($arr as $k=>$v){
$s_arr=explode(',',$v['str']);
$n_arr=explode(',',$v['str']); 《《原来此处是 $n_arr=explode(',',$v[ss]); 提示ss未定义,于是改为 str ,错误消失
foreach($n_arr as $k1=>$n)
$tmp[$k][$n]=$s_arr[$k1];
}
echo "<table>";
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>";
?>
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>';