Jump to content


auto populate a column in another table

callback edit add

  • Please log in to reply
4 replies to this topic

#1 Ahmed Adebiyi Oladapo

Ahmed Adebiyi Oladapo

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 09 September 2016 - 02:21 AM

I have 2 tables i.e Parent and Child. In Parent Table I have Primary Key which is also a Foreign Key in the Child Table.
How can i add new record(s) into the Child table so that the parent ID (Foreign Key) column is automatically populated and linked to a specific parent in the parent table.

 



#2 Athar

Athar

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationNew York

Posted 17 January 2017 - 02:46 PM

Use Triggers


~ I think I think, therefore; I think I exist.


#3 hurtz

hurtz

    Member

  • Members
  • PipPip
  • 15 posts

Posted 17 January 2017 - 03:53 PM

@athar - can you please give an example on how to do this in CI?



#4 Athar

Athar

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationNew York

Posted 17 January 2017 - 05:16 PM

What you want is not a difficult at all if you study grocery crud documents. Lets take the same Parent/Child example. Create a controller by the name of Family as follows.

public function Family()
 {
  $crud = new grocery_CRUD();
  $crud->set_table('child');
  $crud->columns('ID_child','ID_Parent','Child_Name');
  $crud->set_relation('ID_Parent','Parent','Parent_Name');

  $crud->set_subject('List of Children and their Parents');

  $output = $crud->render();
  $this->_example_output($output);
 }

~ I think I think, therefore; I think I exist.


#5 hurtz

hurtz

    Member

  • Members
  • PipPip
  • 15 posts

Posted 18 January 2017 - 06:58 AM

sorry my mistake :(  my mind was floating when i wrote this question, i was thinking of a different scenario. hope didn't bother you much.







1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


    Google (1)