Yii Framework Forum: CDB CRITERIA - Yii Framework Forum

Jump to content

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

CDB CRITERIA tentang query untuk cdbcriteria Rate Topic: -----

#1 User is offline   Fachrizal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 30-November 11

Posted 14 December 2011 - 09:31 PM

gan , mau tanya dong,,,

gmana klo query ane ini dimasukin ke cdbcriteria, gini querynya :

SELECT
a.nik,
a.nama,
b.status,
b.tahun,
b.bulan
FROM rpt0001 a
LEFT JOIN docspkl b
ON a.nik = b.nik
WHERE a.bandposisi = 'VI'
AND a.namaunit = 'blablabla';

mohon bantuaannya gan ....

hasil dari criteria mau dipake di :

return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));


terima kasih....
0

#2 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 14 December 2011 - 10:00 PM

Kalo pake CActiveDataProvider, tabel utamanya biasanya direname jadi `t`.
Harusnya gini.
$criteria = new CDbCriteria(array(
		'select' => array(
			'`t`.`nik`',
			'`t`.`nama`',
			'`b`.`status`',
			'`b`.`tahun`',
			'`b`.`bulan`'),
		'join' => 'LEFT JOIN `docspkl` AS `b` ON `t`.`nik` = `b`.`nik`',
		'condition' => '`t`.`bandposisi` = :bandposisi AND `t`.`namaunit` = :namaunit',
		'params' => array(
			':bandposisi' => 'VI',
			':namaunit' => 'blablabla',
		)
	));

0

#3 User is offline   Fachrizal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 30-November 11

Posted 14 December 2011 - 10:32 PM

View Postpetra, on 14 December 2011 - 10:00 PM, said:

Kalo pake CActiveDataProvider, tabel utamanya biasanya direname jadi `t`.
Harusnya gini.
$criteria = new CDbCriteria(array(
		'select' => array(
			'`t`.`nik`',
			'`t`.`nama`',
			'`b`.`status`',
			'`b`.`tahun`',
			'`b`.`bulan`'),
		'join' => 'LEFT JOIN `docspkl` AS `b` ON `t`.`nik` = `b`.`nik`',
		'condition' => '`t`.`bandposisi` = :bandposisi AND `t`.`namaunit` = :namaunit',
		'params' => array(
			':bandposisi' => 'VI',
			':namaunit' => 'blablabla',
		)
	));



oke terima kasih banyak mas petra ..... ternyata solved ,,, thx yak ...
0

#4 User is offline   ahmadroni 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 250
  • Joined: 14-June 09
  • Location:Yogyakarta-Indonesia

Posted 17 December 2011 - 08:16 PM

Mantab gan.. ternyata udah Solve
Hospital Cost Management System and
Hospital Management Information System
0

#5 User is offline   Vataraxia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-June 12
  • Location:Jakarta

Posted 13 July 2012 - 05:13 AM

gan, mau lanjutin nanya, kalo sql sprti ini:

$tampung = select name from tbl_customer where lower(code) like 'cd%' limit 1;

kalo memakai cdbcriteria jadinya gmn gan?
Where there's a will, there's a way
0

#6 User is offline   Hermans 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 17-February 11

Posted 05 August 2012 - 10:01 PM

Kalau t_customer pakai ActiveRecord (misal Customer namanya).

Pakai ActiveProvider:
$criteria=new CDbCriteria;

$criteria->condition = "lower(t.code) like 'cd%'";
$criteria->limit = 1;
$criteria->order = 'model';
		
		$dataProvider = new CActiveDataProvider("Customer",array(
			'keys'	=> array('product_id'),
			'sort' => array(
					'attributes' => array(
							'model',
						),
				),
			'criteria' => $criteria,
			));


kalau mau langsung pakai sql: Ini
0

#7 User is offline   qikio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 10-August 12
  • Location:Jakarta

Posted 22 August 2012 - 10:13 PM

mau tanya juga, klu sql seperti ini gmn bikin activedataprovidernya?

SELECT p.nama_program AS program, SUM(i.jumlah_definitif) AS pagu
FROM tahun_anggaran t, item i, akun a, suboutput so, komponen k, subkomponen sk, kegiatan kg, program p, dipa d
WHERE d.tahun_anggaran=t.tahun_anggaran AND t.aktif=1 AND i.id_akun=a.id_akun AND a.id_suboutput=so.id_suboutput AND a.id_komponen=k.id_komponen AND a.id_subkomponen=sk.id_subkomponen AND so.id_kegiatan=kg.id_kegiatan AND kg.id_program=p.id_program GROUP BY p.nama_program


Bingung, soalnya tabel 't' nya adalah tabel dipa, tapi ga ada atribut yg perlu dimunculin dari tabel dipa itu sendiri.
0

#8 User is offline   Vataraxia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-June 12
  • Location:Jakarta

Posted 11 September 2012 - 04:32 AM

@Hermans,, very helpful gan,, thanks ;)
Where there's a will, there's a way
0

#9 User is offline   amculin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-July 12

Posted 04 October 2012 - 02:09 AM

Aku ada masalah nih

SQL asli:
SELECT d.id, d.swt_users_id, d.company_desc, d.name, d.company_logo, v.start_date, v.close_date
FROM ccn_employer_data d
JOIN ccn_employer_vacancy v ON d.swt_users_id = v.swt_users_id
WHERE v.online = 1
GROUP BY d.swt_users_id
ORDER BY v.start_date


$dataProvider=new CActiveDataProvider('CcnEmployerData',array(
			'criteria' => array(
				'alias'		=> 'd',
				'select'	=> 'd.id, d.swt_users_id, d.company_desc, d.name, d.company_logo, v.start_date, v.close_date',
				'join'		=> 'JOIN ccn_employer_vacancy v ON d.`swt_users_id` = v.`swt_users_id`',
				'condition'	=> 'v.online = 1 ',
				'group'		=> 'd.swt_users_id',
				'order'		=> $order
			),
			'pagination'=>array(
				'pageSize'=>5,
			)
		));


Kalo pake JOIN gitu kenapa hasil seleksi dari tabel yg dijoin g tampil yah? dalam contoh di atas adalah v.start_date dan v.close_date yang nggak mau tampil..

Ada solusi?
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