码迷,mamicode.com
首页 > 其他好文 > 详细

遍历数据列显示

时间:2016-04-07 20:41:28      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

效果如上图所示:
控制器层 public function actionLists(){ $model = new YueModel; $country = \Yii::$app->db; $o_ids = $country->createCommand("select o_id from orea")->queryAll(); $ids = array(); $names = array(); $count = array(); foreach ($o_ids as $key => $v) { $ids[$key] = $v[‘o_id‘]; } foreach ($ids as $key => $val) { $data =$model->find()->where([‘o_id‘=>$val])->asArray()->all(); $count[]=count($data); $rows[$val] = $data; } $con = max($count); $team = array(); for ($i=0; $i <$con ; $i++) { foreach ($rows as $key => $val) { if(isset($val[$i])){ $team[$i][$key] = $val[$i][‘y_name‘]; } else { $team[$i][$key] = ‘‘; } } } //var_dump($team);//die; return $this->render(‘lists‘,[‘team‘=>$team,‘orea‘=>$orea]); } 视图层 <div> <table border="1"> <tr> <?php foreach($orea as $k=>$v){ ?> <th style="width: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>

遍历数据列显示

标签:

原文地址:http://www.cnblogs.com/jhy-ocean/p/5364977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!