⚠ 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

set_relation to show descriptions from 2 tables...



Charles A.
  • profile picture
  • Member

Posted 23 June 2013 - 20:08 PM

Hi, I have this model:

 

[attachment=584:sample_cars.png]

 

I'm working with a CRUD on CARCODES table... and I would like to show DESCRIPTION (from Brands table) + NAME (from Cars table) replacing the ID_CAR field ... (set_relation, but taking the descriptions from 2 tables) ...

 

Is that possible?

 

So, I have the "carcodes" CRUD.... And I want something like this (replace the ID_FIELD With BRAND and CAR only to show)

 

[attachment=585:carcodes_sample.png]

 

 

... ?


davidoster
  • profile picture
  • Member

Posted 23 June 2013 - 22:01 PM

At least from my point of view the easiest way is to make you own simple model (not by extending the GC model, just a new one!).

Probably the best way to do it is,

 

(sample code, file itemmodel.php under application/models)

 

<?php
class itemmodel extends CI_Model {
    
    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
public function get_healing_techniques_id_description()

{
$query = "SELECT `id`, `description` FROM `groups` WHERE `activities_id` IN (SELECT `id` FROM (`activities`) WHERE  `description`  LIKE 'H-%' ORDER BY `id`)";
$result = $this->db->query($query);
return $result;
}

//... }

 

and then on your controller,

$this->load->model('itemmodel');
		
		// multiple healing techniques
		$healings = $this->itemmodel->get_healing_techniques_id_description();
		foreach ($healings->result() as $row)
		{
			$myarray2[$row->id] .= $row->description;
		}
		$this->grocery_crud->field_type('healing_techniques_ids','multiselect', $myarray2);