สอบถามครับ เราสามารถเรียกแสดง view จาก moudles

wave
final888
1,847
สังคมนักพัฒนาระบบ (Community)
สอบถามครับ เราสามารถเรียกแสดง view จาก moudles

สอบถามครับ เราสามารถเรียกแสดง view จาก moudles อื่นๆมาแสดงในหน้าเดียวกันได้มั้ยครับ
ตอนนี้ผมยัดทุดอย่างไว้ใน ตัว sitecontroller index  หมดเลย run แล้วดูเหมือนทำงานช้า ตัวหน้า index เอาค่าที่ส่งไปไป plot กราฟ ครับ หรือว่าเพราะเป็นกราฟเลยทำให้มันช้า มีแนวทางหรือวิธีแก้ไขยังไงบ้างครับ 
ถ้าเราเรียกแบบตามภาพนี้จะทำให้มันทำงานไวขึ้นมั้ยครับ 

รูปตัวอย่างครับ

   
        $y = isset($_REQUEST['year'])?$_REQUEST['year']:date('Y'); 
        $sql3 = "select  if(vn_stat.age_y BETWEEN '0' and '4' ,'0-4','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '0' and '4' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '0' and '4' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '0' and '4' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '5' and '9' ,'5-9','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '5' and '9' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '5' and '9' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '5' and '9' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '10' and '14' ,'10-14','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '10' and '14' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '10' and '14' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '10' and '14' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '15' and '19' ,'15-19','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '15' and '19' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '15' and '19' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '15' and '19' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '20' and '24' ,'20-24','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '20' and '24' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '20' and '24' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '20' and '24' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '25' and '29' ,'25-29','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '25' and '29' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '25' and '29' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '25' and '29' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '30' and '34' ,'30-34','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '30' and '34' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '30' and '34' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '30' and '34' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '35' and '39' ,'35-39','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '35' and '39' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '35' and '39' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '35' and '39' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '40' and '44' ,'40-44','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '40' and '44' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '40' and '44' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '40' and '44' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '45' and '49' ,'45-49','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '45' and '49' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '45' and '49' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '45' and '49' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '50' and '54' ,'50-54','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '50' and '54' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '50' and '54' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '50' and '54' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '55' and '59' ,'55-59','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '55' and '59' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '55' and '59' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '55' and '59' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '60' and '64' ,'60-64','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '60' and '64' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '60' and '64' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '60' and '64' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '65' and '69' ,'65-69','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '65' and '69' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '65' and '69' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '65' and '69' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '70' and '74' ,'70-74','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '70' and '74' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '70' and '74' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '74' and '74' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '75' and '79' ,'75-79','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '75' and '79' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '75' and '79' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '75' and '79' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '80' and '84' ,'80-84','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '80' and '84' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '80' and '84' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '80' and '84' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '85' and '89' ,'85-89','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '85' and '89' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '85' and '89' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '85' and '89' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '90' and '94' ,'90-94','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '90' and '94' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '90' and '94' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '90' and '94' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y BETWEEN '55' and '99' ,'95-99','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y BETWEEN '95' and '99' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y BETWEEN '95' and '99' and vstdate BETWEEN '$y-01-01' and '$y-12-31') as F 
from vn_stat
where age_y BETWEEN '95' and '99' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age

UNION

select 
if(vn_stat.age_y >= '100' ,'100+','error') as age,
(SELECT count(sex) FROM vn_stat where sex = '1' and age_y >= '100' and vstdate BETWEEN '$y-01-01' and '$y-12-31' ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and age_y >= '100' and vstdate BETWEEN '$y-01-01' and '$y-12-31' ) as F 
from vn_stat
where age_y >= '100' and vstdate BETWEEN '$y-01-01' and '$y-12-31'
GROUP BY age ";
        $data3 = \yii::$app->db->createCommand($sql3)->queryAll();
        $y = isset($_REQUEST['year'])?$_REQUEST['year']:date('Y');
        
$sql4 = " select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())-5),'-01-01') and CONCAT((year(NOW())-5),'-12-31') ) as total ,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())-5),'-01-01') and CONCAT((year(NOW())-5),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())-5),'-01-01') and CONCAT((year(NOW())-5),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())-5),'-01-01') and CONCAT((year(NOW())-5),'-12-31')

UNION

select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())-4),'-01-01') and CONCAT((year(NOW())-4),'-12-31') ) as total,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())-4),'-01-01') and CONCAT((year(NOW())-4),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())-4),'-01-01') and CONCAT((year(NOW())-4),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())-4),'-01-01') and CONCAT((year(NOW())-4),'-12-31')

UNION

select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())-3),'-01-01') and CONCAT((year(NOW())-3),'-12-31') ) as total,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())-3),'-01-01') and CONCAT((year(NOW())-3),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())-3),'-01-01') and CONCAT((year(NOW())-3),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())-3),'-01-01') and CONCAT((year(NOW())-3),'-12-31')


UNION

select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())-2),'-01-01') and CONCAT((year(NOW())-2),'-12-31') ) as total,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())-2),'-01-01') and CONCAT((year(NOW())-2),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())-2),'-01-01') and CONCAT((year(NOW())-2),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())-2),'-01-01') and CONCAT((year(NOW())-2),'-12-31')



UNION

select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())-1),'-01-01') and CONCAT((year(NOW())-1),'-12-31') ) as total,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())-1),'-01-01') and CONCAT((year(NOW())-1),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())-1),'-01-01') and CONCAT((year(NOW())-1),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())-1),'-01-01') and CONCAT((year(NOW())-1),'-12-31')

UNION

select 
DISTINCT(year(vstdate))+543 as year,
(SELECT count(sex) FROM vn_stat where vstdate BETWEEN CONCAT((year(NOW())),'-01-01') and CONCAT((year(NOW())),'-12-31') ) as total ,
(SELECT count(sex) FROM vn_stat where sex = '1' and vstdate BETWEEN CONCAT((year(NOW())),'-01-01') and CONCAT((year(NOW())),'-12-31') ) as M ,
(SELECT count(sex) FROM vn_stat where sex = '2' and vstdate BETWEEN CONCAT((year(NOW())),'-01-01') and CONCAT((year(NOW())),'-12-31') ) as F 
from vn_stat
where vstdate BETWEEN CONCAT((year(NOW())),'-01-01') and CONCAT((year(NOW())),'-12-31') ";
        $data4 = \yii::$app->db->createCommand($sql4)->queryAll();        
        
        
        $sql5 = "SELECT Count(vn_stat.vn) AS count, pttype.pttype, pttype.`name` FROM vn_stat LEFT JOIN pttype ON vn_stat.pttype = pttype.pttype
                where pttype.isuse = 'Y' and vstdate BETWEEN '$y-01-01' and '$y-12-31' GROUP BY pttype    ORDER BY count desc  ";
        $data5 = \yii::$app->db->createCommand($sql5)->queryAll();  
        $y = isset($_REQUEST['year'])?$_REQUEST['year']:date('Y');
        

        
          // คำสั่งที่ นำค่าใส่ตัวแปร 3
        $dataProvider3 = new ArrayDataProvider([
            'allModels' => $data3
        ]);
        
             // คำสั่งที่ นำค่าใส่ตัวแปร 3
        $dataProvider4 = new ArrayDataProvider([
            'allModels' => $data4
        ]);
        
             // คำสั่งที่ นำค่าใส่ตัวแปร 3
        $dataProvider5 = new ArrayDataProvider([
            'allModels' => $data5
        ]);
        
        // คืนค่า 
        return $this->render('index',[
                                
                    'dataProvider3' => $dataProvider3,
                    'dataProvider4' => $dataProvider4,
                    'dataProvider5' => $dataProvider5
        ]);
    }

 

2 ความคิดเห็น

  • final888

  • มานพ กองอุ่น

น่าจะลองสร้างเป็น view แล้ว select เอานะครับ

พอจะมีตัวอย่างมั้ยครับ ^_^