public function actionIndex() { $data = ''; $value = ''; $hosname = ''; //$model = new ChospitalAmp; if (!empty($_POST['hospcode'])) { $value = $_POST['hospcode']; $hosname = ChospitalAmp::findOne(['hoscode' => $value])->hosname; return $this->render('index', ['data' => $value, 'hospcode' => isset($_POST['hospcode']) ? $_POST['hospcode'] : '', 'hosname' => $hosname]); } else { return $this->render('index', ['data' => $data, 'hospcode' => isset($_POST['hospcode']) ? $_POST['hospcode'] : '', 'hosname' => $hosname]); } }
public function actionIndex() { $hospname = ''; $rawData1 = ''; $sql = "select mapp_table,mapp_query from data_hinfo.mas_mapp_main"; if (!empty($_POST['hospcode'])) { $h = $_POST['hospcode']; $m = \frontend\models\ChospitalAmp::findOne(['hoscode' => $h]); $hospname = $m->hosname; } try { $rawData = \Yii::$app->db2->createCommand($sql)->queryAll(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } $count = count($rawData); if (!empty($_POST['hospcode'])) { $dbname = 'db' . $_POST['hospcode']; //$db2 = 'db'; for ($i = 0; $i < 1; $i++) { $sql_command = $rawData[$i]['mapp_query']; $table = $rawData[$i]['mapp_table']; $table = 'tmp_' . $table; $sql = "truncate {$table}"; try { $count_exe = \Yii::$app->db->createCommand($sql)->execute(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } $sql = $sql_command; try { $rawData1 = \Yii::$app->{$dbname}->createCommand($sql)->queryAll(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } $sql = "replace into {$table} select * from person"; try { $exe = \Yii::$app->db->createCommand($sql)->execute(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } } } return $this->render('index', ['hospname' => $hospname, 'hospcode' => isset($_POST['hospcode']) ? $_POST['hospcode'] : '', 'count' => $count, 'rawData' => $rawData, 'rawData1' => $rawData1]); }
public function actionPyramid() { $hospname = ''; $sql = "select substr(t.age_range,3, 10) as age, sum(t.male) as male, sum(t.female) as female \n \t\t\tfrom sys_ages_level_3 t \n \t\t\tgroup by t.age_range"; if (!empty($_POST['hospcode'])) { $h = $_POST['hospcode']; $m = \frontend\models\ChospitalAmp::findOne(['hoscode' => $h]); $hospname = $m->hosname; $sql = "select substr(t.age_range, 3, 10) as age, t.male as male, t.female as female\n \t\tfrom sys_ages_level_3 t\n \t\twhere t.hospcode = {$h}\n \t\tgroup by t.age_range"; } try { $rawData = \Yii::$app->db->createCommand($sql)->queryAll(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } $dataProvider = new \yii\data\ArrayDataProvider(['allModels' => $rawData, 'pagination' => FALSE]); return $this->render('pyramid', ['dataProvider' => $dataProvider, 'rawData' => $rawData, 'hospname' => $hospname, 'hospcode' => isset($_POST['hospcode']) ? $_POST['hospcode'] : '']); }
public function actionPyramid() { //คำนวนอายุประชากร $hosname = ''; $sql = "SELECT SUBSTR(t.age_range,3,10) as age ,SUM(t.male) as male,SUM(t.female)as female from sys_pyramid_level_3 t\n#WHERE t.hospcode ='10612'\nGROUP BY t.age_range"; if (!empty($_POST['hospcode'])) { $h = $_POST['hospcode']; $sql = "SELECT SUBSTR(t.age_range,3,10) as age ,SUM(t.male) as male,SUM(t.female)as female from sys_pyramid_level_3 t\nWHERE t.hospcode ={$h}\nGROUP BY t.age_range"; $m = \frontend\models\ChospitalAmp::findOne(['hoscode' => $h]); $hosname = $m->hosname; } try { $rawData = \Yii::$app->db->createCommand($sql)->queryAll(); } catch (\yii\db\Exception $e) { throw new \yii\web\ConflictHttpException('sql error'); } $dataProvider = new \yii\data\ArrayDataProvider(['allModels' => $rawData, 'pagination' => FALSE]); return $this->render('pyramid', ['dataProvider' => $dataProvider, 'rawData' => $rawData, 'hospcode' => isset($_POST['hospcode']) ? $_POST['hospcode'] : '', 'hosname' => $hosname]); }
?> <div class="site-index"> <p class="lead"> <div class="alert alert-success"> <div class="row"> <div class="col-lg-4" style="text-align: center;"> </div> <div class="col-lg-4" style="text-align: center;"> <p>เลือกสถานบริการสาธารณสุข</p> <form method="POST"> <p> <?php echo Select2::widget(['name' => 'hospcode', 'data' => ArrayHelper::map(ChospitalAmp::find()->all(), 'hoscode', 'hosname'), 'options' => ['placeholder' => empty($hosname) ? 'Select here...' : $hosname]]); ?> </p> <p> <div> <button class = 'btn btn-success'>Search</button> </div> </p> </form> <div id="resp" style="display: none"> <img src="backend\web\images\Processing.gif"> </div> </div> <div class="col-lg-4" style="text-align: center;"> </div>