Welcome Guest, Not a member yet? Register   Sign In
Foreign Key
#1

[eluser]Wondering Coder[/eluser]
hi to all CI community,

I'm just a new to CI. I'm having a problem on how to insert a foreign key in my 2nd table.
The scenario is i have 2 table USERS table & USER_PROFILE TABLE

Code:
users table  -> takes place in the registration
+----------------------------+
user_id |username| password|
  1      admin     admin


user_profile table -> takes place  in the login site of members
+----------------------------+
sp_id | user_id | course | birthdate


How will I able to do this? Any pointers please.
#2

[eluser]Jaketoolson[/eluser]
Shouldn't you be posting this in a MySQL forum or something? If it were me and I needed to make modifications to my database table's schema, I'd do so using SSH, MySQL Query Browser, or shoot even phpMyAdmin. Not Codeigniter.
#3

[eluser]InsiteFX[/eluser]
Get the user_id from the users table

That user_id is the foreign key in the user_profile table.

insert or update the user_profile table using the user_id

time for new keyboard LOL

InsiteFX
#4

[eluser]Wondering Coder[/eluser]
haha,

From searching all related thread here in CI about handling foreign key one of them says that I have to used InnoDB engine, btw I'm using the MySQL default engine MyISAM. Haven't tried it though. Is this really recommended?

Also by reading those user guide in CI I came across HELPERS. So what I did to solved this is just by using $this->db->insert_id().

My model
Code:
$this->db->insert('myTable', $data)
$item = $this->db->insert_id();
$this->save_detail($item);




Theme © iAndrew 2016 - Forum software by © MyBB