热搜:NVER 

php循环

2024-04-26 09:40:02
 php循环

php循环求助

sql查询结果为
year mon
2012 5
2012 4
2012 3
2011 12
2011 11
...

怎么写php循环让它这样输出
2012 
5
4
3
2011
12
11
10
...

------解决方案--------------------
$array=array();

foreach(){
if(isset($array['year'])){
$array['year'][]=$result['mon'];
}else{
$array['year']=$result['year'];
$array['year'][]=$result['mon'];
}

foreach $array print_r;

大概这意思...
------解决方案--------------------
$last = '';
while($r = mysql_fetch_assoc($rs)) {
if($r['year'] != $last) {
echo $r['year'] . '
';
$last = $r['year'];
}
echo $r['mon'] . '
';
}
------解决方案--------------------

探讨

$last = '';
while($r = mysql_fetch_assoc($rs)) {
if($r['year'] != $last) {
echo $r['year'] . '
';
$last = $r['year'];
}
echo $r['mon'] . '
';
}