Yii Framework Forum: gimana caranya nampilin data dari multiple table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

gimana caranya nampilin data dari multiple table Rate Topic: -----

#1 User is offline   AndreMax 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 24-February 11
  • Location:Indonesia,Medan

Posted 02 March 2011 - 11:08 AM

Halo agan-agan Yii Gamers

gan, ae punya table A, simpan: id, name, basic_salary
table B, simpan data: periode, allowance

ane pengen nampilin data kayak gini gan :

Dear %name%
Herewith your monthly salary = %basic_salary%
and allowance = %allowance%
----------------------------------------------
subtotal = %basic_salary% + %allowance%

less :
2% THT -> the formula is 2% * %basic_salary%
-----------------------------------------------
total = %basic_salary% + %allowance% - 2% THT

pigimane sih gan caranye? sejauh ini ane cuma baru tau maenan model, view, gii, crud. jadi untuk manipulasi data dari table belon ngerti. mhon bantuan ya agan2. :)
0

#2 User is offline   mintaraga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 16-April 10
  • Location:Tanggerang, Banten

Posted 02 March 2011 - 04:44 PM

Mo coba bantu nih gan...
mungkin dengan melihat contoh coding dibawah ini bisa membantu:

di Controler (KriteriaController) buat function:
public function actionCreate()
{
	$model=new Kriteria;
	$modelKriteriaGroup=KriteriaGroup::model();
	
	// Uncomment the following line if AJAX validation is needed
	// $this->performAjaxValidation($model);

	if(isset($_POST['Kriteria']))
	{
		$model->attributes=$_POST['Kriteria'];
		if($model->save())
			$this->redirect(array('view','id'=>$model->kriteria_id));
	}

	$this->render('create',array(
		'model'=>$model,
		'modelKriteriaGroup'=>$modelKriteriaGroup,
	));
}


di Model (KriteriaGroup) buat function baru:

public function getDataKriteriaGroup() {
	$sql = "SELECT kriteriagrp_id as kriteriagrp_id ,kriteriagrp_nama as kriteriagrp_nama FROM kriteria_group WHERE 1=:kolKondisi";
	$kondisi = "1";
	$params = array(':kolKondisi'=>$kondisi);
	$dataKriteriaGroup=$this->findAllBySql($sql,$params);
	//$dataKriteriaGroup = $this->findAll();
	if($dataKriteriaGroup!==null) {
		foreach($dataKriteriaGroup as $i => $kriteriaGroup){
			$this->dataKriteriaGroupArray[$kriteriaGroup->kriteriagrp_id] = $kriteriaGroup->kriteriagrp_nama;
		}
	} else {
		$this->dataKriteriaGroupArray[] = array(''=>'None');
	}
	
	return $this->dataKriteriaGroupArray ;
}


kemudian di view (create) bisa dipanggil seperti ini:

<? 
$test = $modelKriteriaGroup->getDataKriteriaGroup();
die(print_r($test));
?>


semoga bisa membantu.
0

#3 User is offline   AndreMax 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 24-February 11
  • Location:Indonesia,Medan

Posted 02 March 2011 - 08:15 PM

satu-satu ane tanyain ya gan, ada yang gak ngerti neh :)

di Model (KriteriaGroup) buat function baru:

public function getDataKriteriaGroup() {
	$sql = "SELECT kriteriagrp_id as kriteriagrp_id ,kriteriagrp_nama as kriteriagrp_nama 
                FROM kriteria_group WHERE 1=:kolKondisi";
	$kondisi = "1";
	$params = array(':kolKondisi'=>$kondisi);
	$dataKriteriaGroup=$this->findAllBySql($sql,$params);
	//$dataKriteriaGroup = $this->findAll();
	if($dataKriteriaGroup!==null) {
		foreach($dataKriteriaGroup as $i => $kriteriaGroup){
			$this->dataKriteriaGroupArray[$kriteriaGroup->kriteriagrp_id] = $kriteriaGroup->kriteriagrp_nama;
		}
	} else {
		$this->dataKriteriaGroupArray[] = array(''=>'None');
	}
	
	return $this->dataKriteriaGroupArray ;
}


ane gak ngerti bagian ini gan
..WHERE 1=:kolKondisi";
	$kondisi = "1";
	$params = array(':kolKondisi'=>$kondisi);


mohon penjelasan ya gan
0

#4 User is offline   mintaraga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 16-April 10
  • Location:Tanggerang, Banten

Posted 03 March 2011 - 04:53 AM

View PostAndreMax, on 02 March 2011 - 08:15 PM, said:

satu-satu ane tanyain ya gan, ada yang gak ngerti neh :)

di Model (KriteriaGroup) buat function baru:

public function getDataKriteriaGroup() {
	$sql = "SELECT kriteriagrp_id as kriteriagrp_id ,kriteriagrp_nama as kriteriagrp_nama 
                FROM kriteria_group WHERE 1=:kolKondisi";
	$kondisi = "1";
	$params = array(':kolKondisi'=>$kondisi);
	$dataKriteriaGroup=$this->findAllBySql($sql,$params);
	//$dataKriteriaGroup = $this->findAll();
	if($dataKriteriaGroup!==null) {
		foreach($dataKriteriaGroup as $i => $kriteriaGroup){
			$this->dataKriteriaGroupArray[$kriteriaGroup->kriteriagrp_id] = $kriteriaGroup->kriteriagrp_nama;
		}
	} else {
		$this->dataKriteriaGroupArray[] = array(''=>'None');
	}
	
	return $this->dataKriteriaGroupArray ;
}


ane gak ngerti bagian ini gan
..WHERE 1=:kolKondisi";
	$kondisi = "1";
	$params = array(':kolKondisi'=>$kondisi);


mohon penjelasan ya gan


itu contoh kalo agan butuh kondisi where gan.
sebenernya agan nggak perlu pake itu juga gak papa tinggal langsung nulis sql nya gan.
saya hanya mencoba mencontohkan param itu bisa digunakan seperti itu.

semoga membantu gan.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users