zoukankan      html  css  js  c++  java
  • 遍历数据列显示

    		
    	控制器层
    
    	public function actionList(){
    		//实例化模型层
    		$area_model = new AreaModel;
    		$team_model = new YueModel;
    		//取出区域表的id和所有数据,队表数据
    		$a_ids = $area_model->find()->select('a_id')->column();
    		$areas = $area_model->find()->asArray()->all();
    		$team = $team_model->find()->asArray()->all();
    		
    		$count = array();
    		$info = array();
    		foreach ($a_ids as $aid) {//1,2,3--6
    			foreach ($team as $key=>$val) {
    				if($val['a_id'] == $aid){
    					$info[$aid][] = $val;
    					$count[]=count($info[$aid]);
    				}				
    			}
    		}
    		//var_dump($count);die;	
    		$con = max($count);
    		$arr = array();
            for ($i=0; $i <$con ; $i++) { 
            	foreach ($info as $key => $val) {
            		if(isset($val[$i])){
            			$arr[$i][$key] = $val[$i]['y_name'];
            		} else {
            			$arr[$i][$key] = '';
            		}
            	}
            }
            //var_dump($arr);die;
    		return $this->render('lists',['team'=>$arr,'area'=>$areas]);
    	}
    
    
    
    		视图层
    
    
    	<div>
    	<table border="1">
    	<tr>
    	<?php foreach($orea as $k=>$v){ ?>
    		
    			<th style="150px"><?php echo $v['o_name'] ?></th>
    
    	<?php } ?>
    	</tr>
    		
    		<?php foreach ($team as $key => $val) {?>
    		<tr>	
    				<?php foreach ($val as $key => $v) {?>
    					<td><?php echo $v; ?></td>
    				<?php } ?>
    		</tr>	
    		<?php } ?>
    			
    	</table>
    	</div>
    
    
  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/jhy-ocean/p/5370601.html
Copyright © 2011-2022 走看看