Page 1 of 1

Using 2 tables

Posted: Thu Jul 30, 2009 11:54 am
by cronika
In my db i have 2 tables: 1 - log in, 2 - other information.
The user will log in and add information on the second table.

My question is: how will i select from second table the information only for the log in user?

Re: Using 2 tables

Posted: Thu Jul 30, 2009 12:17 pm
by jackpf
You'll need a relationship between the primary key in the user's table, and the "other information table" so you can know who to get information for.

Does that make sense? :)

Re: Using 2 tables

Posted: Thu Jul 30, 2009 12:32 pm
by cronika
jackpf wrote:You'll need a relationship between the primary key in the user's table, and the "other information table" so you can know who to get information for.

Does that make sense? :)

From the second table i show get just the id?

Re: Using 2 tables

Posted: Thu Jul 30, 2009 12:41 pm
by jackpf
You'll need a field in the second table to store the ID or whatever the primary key is for the first table in, so that you know whose data it is.

Re: Using 2 tables

Posted: Thu Jul 30, 2009 1:54 pm
by cronika
table 1:
id_table1
user
pass

table 2:
id_table2
information

This is my db.
Can u pls give me an example? I can understand faster and better.

Re: Using 2 tables

Posted: Thu Jul 30, 2009 1:57 pm
by ronnietherocket
table 1:
id_table1<-this should be the primary key for tbl1
user
pass

table 2:
id_table2<-this should be the primary key for tbl2
id_table1
information

Re: Using 2 tables

Posted: Thu Jul 30, 2009 2:09 pm
by cronika
they are primary key but relationship between the primary key in the user's table and the id_table2 so you can know who to get information for. how im doing this?

Re: Using 2 tables

Posted: Thu Jul 30, 2009 2:11 pm
by jackpf
No, id_table1 in table 2 should contain the id_table1 from table 1.

Re: Using 2 tables

Posted: Thu Jul 30, 2009 2:23 pm
by straightman
well, include in the WHERE clause the ID of the logged in user


===========================================================================================

cronika wrote:In my db i have 2 tables: 1 - log in, 2 - other information.
The user will log in and add information on the second table.

My question is: how will i select from second table the information only for the log in user?

Re: Using 2 tables

Posted: Thu Jul 30, 2009 2:37 pm
by straightman
I think what our Romanian guy wants is the query basically


SELECT * FROM informationtable
WHERE logintable.id = informationtable.id;

i have to think that you have linked the tables properly by setting the relationships. Where is your sql code?


Alvaro

===================================================================================








straightman wrote:well, include in the WHERE clause the ID of the logged in user


===========================================================================================

cronika wrote:In my db i have 2 tables: 1 - log in, 2 - other information.
The user will log in and add information on the second table.

My question is: how will i select from second table the information only for the log in user?