⚠ 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

Newbie: Need an AND in relation



donthrash
  • profile picture
  • Member

Posted 24 April 2016 - 14:23 PM

I am new to GC.   I must have a mental block on something.

 

The database has boolean  fields for driver, clerk and active.  I get all the drivers and clerks in the displays but would like only the active people to show up in the add and edit drop downs. Looking for something like "Select firstname, lastname from employee where driver = T AND active = T".

 

Existing code:

$this->grocery_crud->set_relation('driver', 'employee', '{firstname} {lastname}', array('driver' => "T"));

 

Any help would be appreciated,

Don Thrash

 


donthrash
  • profile picture
  • Member

Posted 25 April 2016 - 13:23 PM

Mental block cleared!  The key was the 4th parameter is an 'array'.  I hope this may help another newbie.

 

$state = $this->grocery_crud->getstate();
      if ($state == 'add')

      {
         $this->grocery_crud->set_relation('driver', 'employee', '{firstname} {lastname}', array('driver' => 'T', 'active' => 'T'));
      }

     else

     {
         $this->grocery_crud->set_relation('driver', 'employee', '{firstname} {lastname}', array('driver' => 'T'));
     }