⚠ 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

Insert 1 field to multiple tables



Burhan Ahmed
  • profile picture
  • Member

Posted 23 November 2016 - 08:22 AM

I have two table called users and payments. both at least have attribute like this.

 

users

  • id
  • name
  • number

payments

  • user_number
  • date

and there is one filed called "User Number" if i inserted number to this field, it will be inserted to both users with attribute number and payments with attribute user_number.

 

is it possible?

plz help me to solve this

thx


sfthurber
  • profile picture
  • Member

Posted 02 February 2017 - 14:21 PM

in relational database design the typical practice would be to include in payments table schema the foreign key of the users table.  just a thought.

 

but i'll answer the question you asked. in the crud for one table you would use callbacks to synchronize the corresponding attribute in the other table.

 

the documentation covers how to set up callbacks.

 

in the callback you would use codeigniter's active record classes to do the work.

 

see the codeigniter documentation if you are not familiar with those classes.