⚠ 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

How to use set the select dropdown value field other that the primary value



Flashy
  • profile picture
  • Member

Posted 27 January 2016 - 02:25 AM

When I use the "set_relation" function, how can I use a different database column value for the selects option value that is output?

 

Is the default valued used when rendered the tables Primary key value? - how can I use a value from another column?

 

 

My Code:

 

$this->crud->set_relation('show','statuses','title', array('group' => 'yn'));

 

This is the database structure of the statuses table:

 

CREATE TABLE `statuses` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `value` int(4) NOT NULL DEFAULT '0',
  `group` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

 

 

I want to use the "value" column results not the id column

 


Flashy
  • profile picture
  • Member

Posted 28 January 2016 - 05:11 AM

Worked it out incase anybody else needs to know:

 

Set the primary key of the table before calling set_relations...

 

$crud->set_primary_key('value','statuses');
$crud->set_relation('show_in_navi','statuses','title', array('group' => 'yn'));

 


Flashy
  • profile picture
  • Member

Posted 28 January 2016 - 05:25 AM

 

Worked it out incase anybody else needs to know:

 

Set the primary key of the table before calling set_relations...

 

$crud->set_primary_key('value','statuses');
$crud->set_relation('show_in_navi','statuses','title', array('group' => 'yn'));

 

So it seems that when you do this, it doubles up the data being returned, so I still need an answer to this...


Dennis Ayala
  • profile picture
  • Member

Posted 10 February 2016 - 23:29 PM

So it seems that when you do this, it doubles up the data being returned, so I still need an answer to this...

 

I'm interested to know the answer for this question. Anyone?