Using 2 tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cronika
Forum Commoner
Posts: 27
Joined: Sun Jul 26, 2009 2:28 pm
Location: romania
Contact:

Using 2 tables

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using 2 tables

Post 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? :)
cronika
Forum Commoner
Posts: 27
Joined: Sun Jul 26, 2009 2:28 pm
Location: romania
Contact:

Re: Using 2 tables

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using 2 tables

Post 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.
cronika
Forum Commoner
Posts: 27
Joined: Sun Jul 26, 2009 2:28 pm
Location: romania
Contact:

Re: Using 2 tables

Post 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.
ronnietherocket
Forum Newbie
Posts: 5
Joined: Mon Jul 20, 2009 11:38 am

Re: Using 2 tables

Post 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
cronika
Forum Commoner
Posts: 27
Joined: Sun Jul 26, 2009 2:28 pm
Location: romania
Contact:

Re: Using 2 tables

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using 2 tables

Post by jackpf »

No, id_table1 in table 2 should contain the id_table1 from table 1.
straightman
Forum Commoner
Posts: 48
Joined: Sun Apr 19, 2009 5:20 am

Re: Using 2 tables

Post 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?
straightman
Forum Commoner
Posts: 48
Joined: Sun Apr 19, 2009 5:20 am

Re: Using 2 tables

Post 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?
Post Reply