⚠ 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

Drop downs



Riyaad Salasa
  • profile picture
  • Member

Posted 06 August 2012 - 10:39 AM

I love grocery crud but drop downs are driving me crazy.
From the documentation I understand that I need to use set_relation.

I have reference table called Sub district consisting of
SUB_DISTRICT_ID
SUB_DISTRICT_NAME
ACTIVE

Then I have another table called data status consisting of
DATA_DISPLAY_ID
DATA_DISPLAYNAME

This table basiscally holds 2 rows
Active
Inactive
in the data_displayname column.

When users are adding subdistricts I need them to mark whether it is active or inactive by selecting the correct status from a dropdown
code:
$this->grocery_crud->callback_edit_field('active',array($this,'_call_back_dstatus'));
$this->grocery_crud->callback_add_field('active',array($this,'_call_back_dstatus'));
$this->grocery_crud->display_as('active','Data Status');
$this->grocery_crud->set_relation('active','data_display','data_displayname');

function _call_back_dstatus()
{
$data = $this->getYou('data_display','data_display_id, data_displayname',''); // iam using session here
$hasil ='<select name="active">';
foreach($data as $x)
{
$hasil .='<option value="'.$x->data_display_id.'">'.$x->data_displayname.'</option>';
}
return $hasil.'</select>';
}

function getYou($tabel,$field = '*', $cond ='')
{
$this->db->select($field);
$this->db->from($tabel);
if(!empty($cond)) $this->db->where($cond);
return $this->db->get()->result();
}

Nothing shows up not even the Display as text.

I know the code is being called, if I change a function name etc, it fails.

Any ideas about what I am doing wrong?