CodeIgniter Forums
how do we use multiple tables entry in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how do we use multiple tables entry in codeigniter (/showthread.php?tid=21037)



how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]Sakthi MCA[/eluser]
how can we use multiple tables entry in codeigniter.please give reply immediately.
it is very urgent


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]jedd[/eluser]
have you got one table entry working okay already?


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]Sakthi MCA[/eluser]
i am new to codeigniter.
yes one table entry is working.
i have two tables
one is User_table. it contains user_id (primary,Auto increment) ,User_name and password.
another is profile_table. profile _id(primary,Auto increment) ,user_id ,User_name and password.
i need to store last inserted value of user_id in User_table to user_id field of profile_table.

how can i do in codeigniter

let me know please


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]jedd[/eluser]
Quote: i have two tables
one is User_table. it contains user_id (primary,Auto increment) ,User_name and password.
another is profile_table. profile _id(primary,Auto increment) ,user_id ,User_name and password.

Do you really have User_name and password columns replicated in those two tables?

In any case, you have a user.id (either because you've just done an insert, or a select to find the row you want). And then you do an insert or update query on your profile table and put that value in.

I'm unsure where you're getting stuck. Can you post the model code you've got so far for your insert?


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]jedd[/eluser]
Oh, by the way, how many profiles can one user have?

If your answer is '1' - my next question will be: Why isn't profile_id part of the user table?


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]Sakthi MCA[/eluser]
two profiles

one profile for normal user subscription ie user_table
another for paid user ie profile_table


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]rogierb[/eluser]
To get the last inserted id, use <code>$new_id = $this->db->insert_id();</code> after doing the insert.

Then use that $new_id to update the profile_table.


how do we use multiple tables entry in codeigniter - El Forum - 07-29-2009

[eluser]jedd[/eluser]
[quote author="Sakthi MCA" date="1248891104"]two profiles

one profile for normal user subscription ie user_table
another for paid user ie profile_table[/quote]

Do you mean a user can actually have just one profile (but it can be one of two types) or actually have two different profiles at the same time?

If the former, then your schema is probably broken.

If the latter .. well, your schema is probably broken there too. Wink