php循环

WBOY
Release: 2016-06-13 13:10:11
Original
789 people have browsed it

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'] . '
';
}
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