⚠ 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

Display a concatenated value in drop down list



JustMe
  • profile picture
  • Member

Posted 09 March 2013 - 12:28 PM

 
I am trying to add data to the third table below (classgradeprofile)
I am currently able to display the className in the selection drop down box.
But want I want to do is instead of displaying just the className, I want to 
display "profileName - className" instead.  Not sure how to do this?
I have tried a few variations but to no avail.
 
--Thanks
 
    $crud->set_relation('pkgrp','graderangeprofile','profileName');
    $crud->display_as('pkgrp','Grade Range Profile');
 
 
graderangeprofile
  pkgrp
  profileName
 
classscoreprofile
  pkcsp
  pkgrp (fk to graderangeprofile)
  className
 
classgradeprofile
  pkcgp
  pkcsp (fk to classscoreprofile)
  gradeName

davidoster
  • profile picture
  • Member

Posted 10 March 2013 - 09:10 AM

Because the data you want to display come from two tables you need to :

1. make a model of your own (extend gc model or extend ci model)

2. make a function within your extend model that gets pkgrp and returns the profileName - className

3. within your controller in a function do something similar to this (sample code from a project of mine)

 

$this->load->model('itemmodel');
$activities = $this->itemmodel->get_activities("activities");
foreach ($activities->result() as $row)
{
 $myarray[$row->id] .= $row->description;
}
$this->grocery_crud->field_type('interest_for','multiselect',$myarray);