队伍分组统计 (双重循环遍历出来)或 (sql语句查出来

例1

队伍分组统计 (双重循环遍历出来)或 (sql语句查出来_第1张图片

以上查询语句

1、所有的队伍人员信息: select distinct teamname,realname,users.usertype,clothsize,gender,mobile,address,zipcode,team_users.teamid from users,team_users,team where users.userid = team_users.userid and team.teamid = team_users.teamid and team.matchid = 3ORDER BY team.teamid


2、分组后的队伍人员信息: select distinct teamname,realname,users.usertype,clothsize,gender,mobile,address,zipcode,team_users.teamid from users,team_users,team where users.userid = team_users.userid and team.teamid = team_users.teamid and team.matchid = 3GROUP BY team.teamid


将2分组后的结果当为外循环 比如分组后的队伍teamid为  67,70, 71, 79

将1所有队伍人员信息做为内循环,用67 70 71分别遍历完整个 1 的结果


control层

//得到所有本赛事的报名分组数据,循环遍历进行重构数组数据
		//本赛事队伍分组后的信息group by team.teamid
		$teamInfo = $this->Search_model->getteaminfo($matchid);  
		//本赛事队伍信息,没有group by team.teamid的
		$arrAllTeam = $this->Search_model->getClothSize($matchid); 

		$NewarrTeam = $this->Search_model->constructArrteam($teamInfo,$arrAllTeam);

model层


//重构本赛事所有team信息数据		
			public function constructArrteam($teamInfo,$OldArr){
				$intrecord = 0;
				$teamname = "";
				$headname = "";
				$telphone = "";
				$teamnumber = 0;
				$mname = "";
				$fnmae = "";
				$nucount = 0;//统计每个队伍人数
				$ResturnArr = array();
				
				
				//var_dump($teamInfo);
				//var_dump($teamInfo['34']['teamid']);
				//die();
				
				//var_dump($teamInfo);
				//die();
				
				for($i=0; $i


结果 

队伍分组统计 (双重循环遍历出来)或 (sql语句查出来_第2张图片



例2

队伍分组统计 (双重循环遍历出来)或 (sql语句查出来_第3张图片

对于队数固定,场数为 队数-1时

写入excel时,可以先单独进行队数写入。再用数组把队数-1的值给新数组中。 再单独插入场数

//先放队数
		if($GroupTypeSummary){
			$intrecord = 2;
			
			for($i=0; $igetActiveSheet()->setCellValue('A'.$intrecord, $GroupName[$i]['groupname']);   
				}
				$nu = 0;
				for($j = 0;$j < count($EventType);$j++){										
										
					 
					$objPHPExcel->getActiveSheet()->setCellValue($arrCellLetter[$nu].$intrecord, $GroupTypeSummary[$i][$j]);
				$nu = $nu + 2;
				}
				

			}


			
			
		}else{
			
		}

		//再放场数,场数为队数-1,重新循环队数将场数值得到

			$fieldnumber = array();
			$num = 0; //队数给于变量num
			if($GroupTypeSummary){
			$intrecord = 2;
			
			for($i=0; $igetActiveSheet()->setCellValue($arrCellLetter[$nu].$intrecord, $fieldnumber[$i][$j]);
		
					$nu = $nu + 2;
				}
			}	

			}else{
			
		}


===========================================================

sql语句查出来

SELECT m.eventtypeid, m.eventgroupid,Count(*) as Num, typename, groupname
FROM (SELECT tf.teamid, e.eventid, e.eventtypeid, e.eventgroupid, t.status
FROM teamform tf, events e, team t WHERE tf.matchid = 3 AND tf.eventid = e.eventid AND tf.teamid = t.teamid) AS m
left JOIN eventtype on eventtype.eventtypeid = m.eventtypeid
left join eventgroups on m.eventgroupid = eventgroups.eventgroupid
GROUP BY m.eventtypeid,m.eventgroupid ORDER BY m.eventgroupid, m.eventtypeid

队伍分组统计 (双重循环遍历出来)或 (sql语句查出来_第4张图片


你可能感兴趣的:(php数组)