How To Insert Multi Query In Pdf Report Using Yii Framework

hello everyone, can you help me, i have problem with query, how i can be call query $data into $pdf, because i try to give <?php echo $data[0]['address'?>

this is my full code of Controller :

    class BeasiswaController extends Controller 


   {


   public funtion actionIndex()


   }


	$_nim = Yii::app()->user->name;


	$_smt = Yii::app()->user->smt;


	$dbCommand = Yii::app()->db->createCommand("set @sum := 0;");


	$dbCommand->execute();


	$sql = 


	// "set @sum := 0;"


     "select "


	 


	. " dat_mahasiswa.nama_mhs, dat_mahasiswa.almt_mhs, dat_mahasiswa.tgl_lhr_mhs, dat_mahasiswa.tmp_lhr_mhs, tab_program_studi.nama_pst, tab_program_studi.fakultas, case(dat_mahasiswa.kd_jenis) when 'B' then 'S-2' else case (dat_mahasiswa.kd_jenis) when 'C' then 'S-1' else 'D-3' end end as jenjang,case left(dat_mahasiswa.kd_kls,1) when '0' then mid(dat_mahasiswa.kd_kls,2,1) else mid(dat_mahasiswa.kd_kls,1,2) end semt"


	. " from dat_mahasiswa, tab_program_studi" 


	. " where dat_mahasiswa.nim_mhs='$_nim' and tab_program_studi.kd_pst = dat_mahasiswa.kd_pst;";


	 


	$dbCommand = Yii::app()->db->createCommand($sql);


	$data = $dbCommand->queryAll($dbCommand);


	


	require_once ("protected/extensions/fpdf17/fpdf.php");


	$pdf=new PDF('P','mm','A4');


	$pdf->AddPage();


	$pdf->SetFont('Arial','',12);


	$pdf->SetFont('Times','B','14');


	$pdf->Cell(0,7,'','0',1,'C');


	$pdf->Cell(0,1,'SURAT KETERANGAN BEASISWA','0',1,'C');


	$pdf->Cell(0,0,'_________________________________','0',1,'C');


	$pdf->SetFont('Times','','12');


	$pdf->Cell(0,12,'Nomor: ............................................................................','0',1,'C');


	


	$pdf->Ln();


	$pdf->SetFont('Times','','12');


	$pdf->Cell(0,10,'Universitas , dengan ini menerangkan bahwa:','0',1,'L');


	$pdf->Cell(0,8,'','0',1,'L');


	


	$nama = array(


	array("label"=>"Nama","length"=>40, "align"=>"L"),


	array("label"=>':',"length"=>5, "align"=>"L"),


	array("label"=>Yii::app()->user->nama_mhs,"length"=>43, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($nama as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


	


	$pdf->Cell(0,6,'','0',1,'L');	





	$nim = array(


			array("label"=>"NIM","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>Yii::app()->user->nim_mhs,"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($nim as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,6,'','0',1,'L');





	$tempat = array(


			array("label"=>"Tempat/Tanggal Lahir","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>35, "align"=>"L"),


			array("label"=>'/',"length"=>2, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),





	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($tempat as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,6,'','0',1,'L');





	$alamat = array(


			array("label"=>"Alamat","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($alamat as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,14,'','0',1,'L');


	$pdf->Cell(0,2,'Adalah benar yang bersangkutan adalah Mahasiswa  pada:','0',1,'L');





	$pdf->Cell(0,10,'','0',1,'L');





	$pst = array(


			array("label"=>"Program Studi","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($pst as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}





	$pdf->Cell(0,6,'','0',1,'L');





	$fakultas = array(


			array("label"=>"Fakultas","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($fakultas as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,6,'','0',1,'L');





	$Jenjang = array(


	array("label"=>"Jenjang Pendidikan","length"=>40, "align"=>"L"),


	array("label"=>':',"length"=>5, "align"=>"L"),


	array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($Jenjang as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


	


	$pdf->Cell(0,6,'','0',1,'L');





	$Semester = array(


			array("label"=>"Semester","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($Semester as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,6,'','0',1,'L');





	$Tahun = array(


			array("label"=>"Tahun Akademik","length"=>40, "align"=>"L"),


			array("label"=>':',"length"=>5, "align"=>"L"),


			array("label"=>'',"length"=>5, "align"=>"L"),


	);


		$pdf->SetFont('Times','','12');


		$pdf->SetFillColor(255,255,255);


		$pdf->SetTextColor(0);


		$pdf->SetDrawColor(250, 235, 215);


		foreach ($Tahun as $kolom) {


			$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);


		}


		


	$pdf->Cell(0,10,'','0',1,'L');


	$pdf->Cell(0,8,'Dengan ini kami terangkan bahwa yang bersangkutan berkelakuan baik dan belum memperoleh beasiswa','0',1,'L');


	$pdf->Cell(0,2,'dari pihak manapun.','0',1,'L');





	$pdf->Cell(0,10,'','0',1,'L');


	$pdf->Cell(0,2,'Demikian surat keterangan ini kami buat, untuk dapat dipergunakan sebagaimana mestinya.','0',1,'L');





	$pdf->Cell(0,12,'','0',1,'L');


	$pdf->Cell(0,6,', ...........................        ','0',1,'R');


	$pdf->Cell(0,6,'a.n. Rektor                                   ','0',1,'R');


	$pdf->Cell(0,6,'Ketua Program Studi                   ','0',1,'R');


	$pdf->Cell(0,10,'','0',1,'R');


	$pdf->Cell(0,15,'..............................................       ','0',1,'R');





		


	$pdf->Output("Beasiswa.pdf","I");


	echo "PDF file is generated successfully!";


}





// Uncomment the following methods and override them if needed


/*


public function filters()


{


	// return the filter configuration for this controller, e.g.:


	return array(


		'inlineFilterName',


		array(


			'class'=>'path.to.FilterClass',


			'propertyName'=>'propertyValue',


		),


	);


}


}

Thank You Before.

Hi, this is indonesian forum, so i’m guessing you speak indonesian, i’ll try to describe my approach in bahasa indonesia.

Pertama, selamat datang di Yii, anda naik kelas dari gaya programming yg lama ke gaya koding yg lebih terstruktur dan insya Allah lebih baik.

Kalo pake yii, ada baiknya anda sempatkan coba yg dasar2 seperti user guide, atau langsung praktek bikin blog.

untuk ngerjain tugas di atas, ada baiknya anda pecah kodingnya ke 3 tempat, biar gampang debuging masalahnya ada di mana, saran saya controllernya disederhanakan jadi gini:




    class BeasiswaController extends Controller 

	   {

       public funtion actionIndex()

       {

        $_nim = Yii::app()->user->nim_mhs;

        $_nama = Yii::app()->user->nama_mhs;


        $daftarBeasiswa = Mahasiswa::model()->getBeasiswa($_nim);


        $this->renderPartial('pdf_print', array(

        	'nim'=>$_nim,

        	'nama'=>$_nama,

        	'daftarBeasiswa'=>$daftarBeasiswa,

        ));

		Yii::app()->end();

	}

	

	// Uncomment the following methods and override them if needed

	/*

	public function filters()

	{

		// return the filter configuration for this controller, e.g.:

		return array(

			'inlineFilterName',

			array(

				'class'=>'path.to.FilterClass',

				'propertyName'=>'propertyValue',

			),

		);

	}

    }



kemudian code untuk narik data siswa masukkan bareng protected/models/mahasiswa.php




<?php

  class Mahasiswa extends CActiveRecord {

  ...

  public function getBeasiswa($nim) {

		$sql = 

	     "select dat_mahasiswa.nama_mhs, dat_mahasiswa.almt_mhs, dat_mahasiswa.tgl_lhr_mhs, dat_mahasiswa.tmp_lhr_mhs, tab_program_studi.nama_pst, tab_program_studi.fakultas, case(dat_mahasiswa.kd_jenis) when 'B' then 'S-2' else case (dat_mahasiswa.kd_jenis) when 'C' then 'S-1' else 'D-3' end end as jenjang,case left(dat_mahasiswa.kd_kls,1) when '0' then mid(dat_mahasiswa.kd_kls,2,1) else mid(dat_mahasiswa.kd_kls,1,2) end semt"

		. " from dat_mahasiswa, tab_program_studi" 

		. " where dat_mahasiswa.nim_mhs='$_nim' and tab_program_studi.kd_pst = dat_mahasiswa.kd_pst;";

		 

		$dbCommand = Yii::app()->db->createCommand($sql);

		return $dbCommand->queryAll();

  }

  ...

  }



lalu kodingan panjang tcpdf, masukin ke dalam view sendiri di protected/views/beasiswa/pdf_print.php




		require_once ("protected/extensions/fpdf17/fpdf.php");

		$pdf=new PDF('P','mm','A4');

		$pdf->AddPage();

		$pdf->SetFont('Arial','',12);

		$pdf->SetFont('Times','B','14');

		$pdf->Cell(0,7,'','0',1,'C');

		$pdf->Cell(0,1,'SURAT KETERANGAN BEASISWA','0',1,'C');

		$pdf->Cell(0,0,'_________________________________','0',1,'C');

		$pdf->SetFont('Times','','12');

		$pdf->Cell(0,12,'Nomor: ............................................................................','0',1,'C');

		

		$pdf->Ln();

		$pdf->SetFont('Times','','12');

		$pdf->Cell(0,10,'Universitas , dengan ini menerangkan bahwa:','0',1,'L');

		$pdf->Cell(0,8,'','0',1,'L');

		

		$nama = array(

		array("label"=>"Nama","length"=>40, "align"=>"L"),

		array("label"=>':',"length"=>5, "align"=>"L"),

		array("label"=>$nama,"length"=>43, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($nama as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

		

		$pdf->Cell(0,6,'','0',1,'L');	

	

		$nim = array(

				array("label"=>"NIM","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>$nim,"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($nim as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,6,'','0',1,'L');


		$tempat = array(

				array("label"=>"Tempat/Tanggal Lahir","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>35, "align"=>"L"),

				array("label"=>'/',"length"=>2, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),


		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($tempat as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,6,'','0',1,'L');


		$alamat = array(

				array("label"=>"Alamat","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($alamat as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,14,'','0',1,'L');

		$pdf->Cell(0,2,'Adalah benar yang bersangkutan adalah Mahasiswa  pada:','0',1,'L');


		$pdf->Cell(0,10,'','0',1,'L');


		$pst = array(

				array("label"=>"Program Studi","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($pst as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}


		$pdf->Cell(0,6,'','0',1,'L');


		$fakultas = array(

				array("label"=>"Fakultas","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($fakultas as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,6,'','0',1,'L');


		$Jenjang = array(

		array("label"=>"Jenjang Pendidikan","length"=>40, "align"=>"L"),

		array("label"=>':',"length"=>5, "align"=>"L"),

		array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($Jenjang as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

		

		$pdf->Cell(0,6,'','0',1,'L');


		$Semester = array(

				array("label"=>"Semester","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($Semester as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,6,'','0',1,'L');


		$Tahun = array(

				array("label"=>"Tahun Akademik","length"=>40, "align"=>"L"),

				array("label"=>':',"length"=>5, "align"=>"L"),

				array("label"=>'',"length"=>5, "align"=>"L"),

		);

			$pdf->SetFont('Times','','12');

			$pdf->SetFillColor(255,255,255);

			$pdf->SetTextColor(0);

			$pdf->SetDrawColor(250, 235, 215);

			foreach ($Tahun as $kolom) {

				$pdf->Cell($kolom['length'], 3, $kolom['label'],0, '0', $kolom['align'], true);

			}

			

		$pdf->Cell(0,10,'','0',1,'L');

		$pdf->Cell(0,8,'Dengan ini kami terangkan bahwa yang bersangkutan berkelakuan baik dan belum memperoleh beasiswa','0',1,'L');

		$pdf->Cell(0,2,'dari pihak manapun.','0',1,'L');


		$pdf->Cell(0,10,'','0',1,'L');

		$pdf->Cell(0,2,'Demikian surat keterangan ini kami buat, untuk dapat dipergunakan sebagaimana mestinya.','0',1,'L');


		$pdf->Cell(0,12,'','0',1,'L');

		$pdf->Cell(0,6,', ...........................        ','0',1,'R');

		$pdf->Cell(0,6,'a.n. Rektor                                   ','0',1,'R');

		$pdf->Cell(0,6,'Ketua Program Studi                   ','0',1,'R');

		$pdf->Cell(0,10,'','0',1,'R');

		$pdf->Cell(0,15,'..............................................       ','0',1,'R');


			

		$pdf->Output("Beasiswa.pdf","I");

//echo "PDF file is generated successfully!"; --->bikin error



sampe sini mestinya anda udah bisa nampilin PDF yg isinya baru header dilengkapin nim dan nama siswa (belum daftar siswanya), tapi kalo masih ada error, jadi lebih mudah nyarinya. apa masih ada error?

  • waktu tarik datanya?

  • waktu nampilin datanya?

  • atau lainnya?

Thank’s Om daudtm sebelumnya, disini saya hanya meneruskan source yang sudah dibuat oleh senior saya yang terdahulu, saya hanya mengikuti bagaimana struktur yang dibuat saja, sebelumnya thank’s saya sudah di ajarkan, ini menambah wawasan saya. ;D