php循环
Jun 13, 2016 am 10:52 AM
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'] . '
';
}
------解决方案--------------------

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations

Sort array using Array.Sort function in C#

Implementing distributed task scheduling using Golang's web framework Echo framework

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?

Detailed explanation of the role and usage of the echo keyword in PHP

Simple and clear method to use PHP array_merge_recursive() function

Explore the Go language framework: 5 choices not to be missed!
