zoukankan      html  css  js  c++  java
  • yii遍历行下的每列数据(小1月考)

    效果图:

    控制器(1种):

        //显示列表
        public function actionList()
        {
            //实例化对象
            $model= new Qiu();
            $country = Yii::$app->db;
            //查询数据
            $data = $country->createCommand("select * from qiu join region on qiu.region_id=region.region_id")->queryAll();
            $region_ids = $country->createCommand("select region_id from region")->queryAll();
            $region = $country->createCommand("select * from region")->queryAll();
            //遍历数组
            $ids = array();
            $names = array();
            $count = array();
            //遍历区域ID
            foreach ($region_ids as $key => $v)
            {
                $ids[$key] = $v['region_id'];
            }
            //print_r($ids);die;
            //遍历球队
            foreach ($ids as $key => $val)
            {
                $data =Qiu::find()->where(['region_id'=>$val])->asArray()->all();
                $count[]=count($data);
                $rows[$val] = $data;
            }
            //print_r($rows);die;
            //根据所有记录进行遍历,显示最多行数
            $ji =  max($count);
            $arr = array();
            //找出对应的球队
            for($i=0;$i<$ji;$i++)
            {
                foreach($rows as $key => $val)
                {
                    if(isset($val[$i]))
                    {
                        $arr[$i][$key] = $val[$i]['q_name'];
                    }
                    else
                    {
                        $arr[$i][$key] = '';
                    }
                }
            }
            //var_dump($arr);die;
            //分配数据
            return $this->render('list',['arr'=>$arr,'region'=>$region]);
        }

    (2种):
     
        public function actionList1()
       {
            //实例化模型层
            $region = new Region;
            $qiu = new Qiu;
            //取出区域表的iQiud和所有数据,队表数据
            $region_ids = $region->find()->select('region_id')->column();
            $areas = $region->find()->asArray()->all();
            $team = $qiu->find()->asArray()->all();
            
            $count = array();
            $info = array();
            foreach ($region_ids as $aid) {//1,2,3--6
                foreach ($team as $key=>$val) {
                    if($val['region_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]['q_name'];
                    } else {
                        $arr[$i][$key] = '';
                    }
                }
            }
            //var_dump($arr);die;
           return $this->render('list',['arr'=>$arr,'region'=>$areas]);
        }

    视图层:

             <table border="1">
             <!--一行区域-->
             <tr style="background:red;">
             <?php foreach ($region as $key => $v1) {?>
             <td><?php echo $v1['region_name']; ?></td>
             <?php }?>
             </tr>

             <!--每列球队-->
             <?php foreach ($arr as $key => $val) {?>
             <tr>    
             <?php foreach ($val as $key => $v) {?>
             <td><?php echo $v; ?></td>
             <?php } ?>
             </tr>    
             <?php } ?>
             </table>

  • 相关阅读:
    使用WinDbg调试SQL Server——入门
    SQL Server里如何随机记录集
    相关列的基数计算
    自增长的聚集键值不会扩展(scale)
    使用正确的筛选参数来提高查询性能
    可更新聚集列存储索引幻想
    在SQL Server 2014里可更新的列存储索引 (Updateable Column Store Indexes)
    SQL Server 2014里的IO资源调控器
    SQL Server 2014里的针对基数估计的新设计(New Design for Cardinality Estimation)
    缓存池扩展 (Buffer Pool Extension)实践
  • 原文地址:https://www.cnblogs.com/shaohuixia/p/5364121.html
Copyright © 2011-2022 走看看