⚠ 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

Interdependent select lists



alvarito
  • profile picture
  • Member

Posted 19 September 2012 - 13:32 PM

Hello


I have on my frontpage the typical set of 3 interdependent select lists, which work fine. eg country region and city.

Now I am building the back office and the question is how do I do region and city ?

it would have to be of course with the "where" clause, where "WHERE" is equal to the country selected, so the FK of region will be = to the PK of countries table.

I know there is a set n relation and that there is a where parameter (the 4th) yet, the example it gives
,[color=#000066]array[/color][color=#66cc66]([/color][color=#ff0000]'status'[/color] => [color=#ff0000]'active'[/color][color=#66cc66])[/color][color=#66cc66])[/color];

seems to refer to a single table, but I want to say where regions_table.id_country = country_table.id_country

any approach or solution to this?

regards

Alvaro

midnigther
  • profile picture
  • Member

Posted 19 September 2012 - 13:51 PM

Check the CI database documentation.
http://codeigniter.com/user_guide/database/active_record.html

alvarito
  • profile picture
  • Member

Posted 20 September 2012 - 16:55 PM

Hello

hm, I mean, I have it working on Codeigniter myself, what I mean is to have it working in the Crud editor in the backoffice.

I have this for countries

$crud->set_relation('id_country','countries','nane_country');

now I would need that the region

is dependent on what has been chosen above. Like said, I have it on codeigniter working fine and I have read that the where clause is the same in crud as in codeigniter, yet

I don't know how to mix the

set_relation and the where

something like this should be: $crud->set_relation('id_region', 'regiones', 'nombre_region')->where('regiones.id_country','countries.id_country');

midnigther
  • profile picture
  • Member

Posted 20 September 2012 - 17:56 PM

Try this.


void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] )
...
$crud->set_relation ('id_country', 'countries','nane_country', '[color=#282828][font=helvetica, arial, sans-serif]regions_table.id_country = country_table.id_country');[/font][/color]

alvarito
  • profile picture
  • Member

Posted 21 September 2012 - 16:43 PM

Thank you very much in advance!

I will try it.

best regards

Alvaro

[quote name='midnigther' timestamp='1348163767' post='3553']
Try this.


void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] )
...
$crud->set_relation ('id_country', 'countries','nane_country', '[color=#282828][font=helvetica, arial, sans-serif]regions_table.id_country = country_table.id_country');[/font][/color]

[/quote]