⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Error Query On Set Relation



dimazarno
  • profile picture
  • Member

Posted 21 February 2014 - 07:15 AM

Hi all,

 

I want to know is set_relation function can be nested like this :

 

$crud->set_relation('idph','mkt_ph','{no} - {(SELECT mkt_customer.nama FROM mkt_customer WHERE mkt_ph.idcustomer = mkt_customer.id)}','status_project <> "Selesai"');

This give me error

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' mkt_customer.nama FROM mkt_customer WHERE mkt_ph.idcus' at line 1

SELECT mkt_ph.id, CONCAT('', COALESCE(no, ''), ' - ', COALESCE((SELECT mkt_customer.nama FROM mkt_customer WHERE mkt_ph.idcustomer = mkt_customer.id), ''), '') as s374da55c FROM (`mkt_ph`) WHERE `status_project` <> "Selesai" ORDER BY `s374da55c`

Filename: D:\xampp\htdocs\ss\system\database\DB_driver.php

But if i try run the sql that generate from the error above to phpmyadmin->mysql , it work (please see attachment).

 

 

I dont know, is it problem with codeigniter or GC not functioned for this.

 

Thanks.


connard
  • profile picture
  • Member

Posted 03 March 2014 - 14:51 PM

Hey, you shouldn't need a query when you set a 1-n relation or a n-n relation, can you show your table structures and what you want to get?


dimazarno
  • profile picture
  • Member

Posted 04 March 2014 - 03:12 AM

This is my table structure (attachment)

 

My code :

$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('fin_proforma');
.
.
.		
$crud->columns('datetime_request','idph','isread','datetime_read','isdone','datetime_done','no');
$crud->fields('idph','digunakan_untuk','end_user','jenisdiskon','single_diskon','Produk','terupdate'
		,'jenispajak','kondisi','reff','upload_reff','ongkir','dp','keterangan_mkt','keterangan_mkt_to_produksi','iduser_mkt','datetime_request');		
.
.		
//my problem here (i want to show field `no` from `mkt_ph` and `nama` from `mkt_customer` 
$crud->set_relation('idph','mkt_ph','{no} - {nama?}','status_project <> "Selesai"');
.
.		
$output = $crud->render();
.
.

My goal is: i want to show field `no` from `mkt_ph` and `nama` from `mkt_customer`

 

Thanks.

 

 


Amit Shah
  • profile picture
  • Member

Posted 04 March 2014 - 04:58 AM

dudes... instead of complicating life out there - i will suggest u to use the following

http://www.grocerycrud.com/documentation/options_functions/field_type#dropdown-field

 

here u can generate the  array of your required value in an array format and apply it to the field rather then setting a relation to it.

 

Happy GCing:)


dimazarno
  • profile picture
  • Member

Posted 06 March 2014 - 07:07 AM

Thanks Amit Shah!