Mysql PHP Myadmin Help

Joined
Aug 4, 2010
Messages
573
Reaction score
178
I have this website where the user logs in and it displays their information and of course each other is assigned with a session ID which ?= [1][2][3] etc.

So per say I login with ID 1, and I can retrieve all my information from a table since its all in 1 TABLE.

How can I make a new table with new columns but keep the users ID's.

I don't know if i'm clear enough but i'll say it like this.

This is the original table with the users information..
TABLE (USERS) = [id] [name] [lastname] [password] [password2] [street] [city] [province]

This is another table that I want to make but still have its information connected to table 1.
TABLE (UserINFO) = [id] [coins] [friends] [votes]

so if I want to call it in a query like so

SELECT coins FROM UserInfo WHERE id = $_SESSION['user_id'] .

Would I have to have it insert the users ID from when they first register into UserInfo on the website ? or would I have to have it Insert new information into the new table. <-- Come to think of it I think I answered my own question.


But give me info on what I should do, Is it the JOIN function I need to use??
 
When creating a record in the coins table you would insert the users ID. This value and the value in your Users table are completely independent but you're using the ID of "Coins" as a foreign key to the Users table.

This will be useful #1 because of the relation of the two tables, but it will also make selecting both tables using a join easy.

Example of an inner join needed to select the records of both tables as one record (note that an inner join will only work if the record exists in both tables. If you could possibly not have a value in the "Coins" table, you'll want to use an outer join.

Code:
Select * from Users A INNER JOIN Coins B on A.ID = B.ID Where A.ID = 'UsersID';
 
Back