⚠ 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

add to relation table without clicking dropdown



DREON
  • profile picture
  • Member

Posted 28 April 2013 - 23:01 PM

i have 2 tables called

 

faculty_list with fields id,fname,lname,middle

 

and

ftraining_log with  with fields id,faculty_list_id(related to faculty_list), inclusive_period,inhouse ,outside

 

on my code below i have an view: see on my pic aatached:

 

the below code i can add more details on my faculty_list using my relation table ftraining_log

 

and that details will view one of my faculty_list by clicking faculty_list_id(related to faculty_list) dropdown.

 

example:  on my attached image:

 

on my faculty_list table i have add_action called View, when you click that View button on one of my list

example, Cruz, Robert and you will go to ftraining_log view the code below, and when i click add

the image i attached thats the view:

 

now my question is how can i add ftarining_log details that belongs to cruz, robert without clicking

the dropdown faculty_list_id(related to faculty_list) or from the field Faculty Name.

 

 

-----------------------------------------------------------------------------------  
    function training_faculty($primary_key)
 {
        if (!$this->ion_auth->is_admin())
        {
            $this->session->set_flashdata('message', 'You must be an admin to view this page!!');
            redirect('welcome/index');
        }
        $crud = new grocery_CRUD();
 
        $crud->set_theme('datatables');
        $crud->set_table('ftraining_log');
        $crud->set_subject('Training');
        $crud->columns('inclusive_period','inhouse','outside','date_add');
                
        $crud->set_relation('faculty_list_id','faculty_list','{lname},{fname}');    
        
        
        
        $crud->field_type('date_add','hidden');
        
        $crud->display_as('faculty_list_id','Faculty Name');
        $crud->display_as('inclusive_period','Inclusive Period');
        $crud->display_as('inhouse','In-House');
        $crud->display_as('outside','Outside');
        $crud->display_as('date_add','Date Incoded');
         $crud->required_fields('faculty_list_id');    
        
        $crud->callback_before_insert(array($this,'callback_ftraining'));
    
        $crud-> where('faculty_list_id',$primary_key);  // primary_key has the id from the faculty_cmt table
        

        $data = $this->db->get_where('faculty_list',array('id'=>$primary_key))->row_array();
        
        $output = $crud->render();
        $output->output = '<div align="center"> <b>'."Below List". '</b></div>'.$output->output;
        $output->output = '<h1><div align="center"> <b>'.$data['lname'] .", " .$data['fname'].'</b></div></h1>'.$output->output;
        
    
       $this->load->view('admin/ftraining_log',$output);


DREON
  • profile picture
  • Member

Posted 02 May 2013 - 23:22 PM

help


victor
  • profile picture
  • Member

Posted 03 May 2013 - 13:47 PM

use callback_field function to make that

DREON
  • profile picture
  • Member

Posted 03 May 2013 - 14:09 PM

thank you for fast reply sir victor.

 

but im new to Gc and CI, can you give me some example code to get my problem.. many thanx to you sir victor.


victor
  • profile picture
  • Member

Posted 03 May 2013 - 14:16 PM

www.grocerycrud.com/documentation/options_functions/callback_edit_field
you can create html as you like and return it.
I'm typing the message using phone. I can't type php code.

DREON
  • profile picture
  • Member

Posted 03 May 2013 - 14:41 PM

thak you sir victor, ill wait when you type php code.. :) .

 

sorry because i dont get the logic, thats why i need a sample php code.. thnx again sir victor..


DREON
  • profile picture
  • Member

Posted 07 May 2013 - 14:45 PM

help please


victor
  • profile picture
  • Member

Posted 08 May 2013 - 19:11 PM



// add a new property
protected $faculty_list_id

function training_faculty($primary_key=NULL) { 
//........ 
if($primary_key==NULL)show_404();
$this->faculty_list_id = $primary_key;
//.....
$crud = new gc...
$crud->callback_edit_field('faculty_list_id',array($this,'callback_function'));
}

function callback_function()
{
$result = $this->db->get_where('faculty_list',array('faculty_list_id',array('faculty_list_id'=>$this->faculty_list_id))->row_array();
return '<input type="hidden" name="faculty_list_id" value="'.$this->faculty_list_id.'"> <srong>'.$result['fname'].'</strong>';
}

DREON
  • profile picture
  • Member

Posted 08 May 2013 - 23:02 PM

thank you sir for your big help itry  your code

 

    $crud->callback_add_field('faculty_list_id',array($this,'callback_add'));

 

  function callback_add()
{
$result = $this->db->get_where('faculty_list',array('faculty_list_id',array('faculty_list_id'=>$this->faculty_list_id))->row_array();
return '<input type="hidden" name="faculty_list_id" value="'.$this->faculty_list_id.'"> <srong>'.$result['fname'].'</strong>';
}

 

i got this error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR


victor
  • profile picture
  • Member

Posted 09 May 2013 - 06:59 AM

change

array('faculty_list_id',array('faculty_list_id'=>$this->faculty_list_id);

into

array('faculty_list_id'=>$this->faculty_list_id);


DREON
  • profile picture
  • Member

Posted 09 May 2013 - 07:35 AM

thank you sir victor:

 

function callback_add()
            {
            $result = $this->db->get_where('support_list',array('support_list_id',array('support_list_id'=>$this->support_list_id)));
            return '<input type="hidden" name="support_list_id" value="'.$this->support_list_id.'"> <srong>'.$result['fname'].'</strong>';
            }

 

i got this error sir:

 

Unknown column '0' in 'where clause'

SELECT *
FROM (`faculty_list`)
WHERE `0` = 'faculty_list_id'
AND `1` = Array

 

sir victor like what i attached on my first post what i want when i click add on

 

One of my list example robert crud the Fullname should already fill out by the name Robert cruz


victor
  • profile picture
  • Member

Posted 09 May 2013 - 08:09 AM

look at the last post!!!
you have a wrong code.

DREON
  • profile picture
  • Member

Posted 09 May 2013 - 08:26 AM

got it sir victor thnak you so much:

 

    $result = $this->db->get_where('faculty_list',array('id'=>$this->faculty_list_id))->row_array();
            return '<input type="hidden" name="faculty_list_id" value="'.$this->faculty_list_id.'"> <srong>'.$result['fname'].'</strong>';


victor
  • profile picture
  • Member

Posted 09 May 2013 - 08:50 AM


this-> db->get_where('table',array('faculty_list_id'=>$this->faculty_list_id))...

victor
  • profile picture
  • Member

Posted 09 May 2013 - 08:51 AM

good luck!