Hello everyone.

Basically, I am making a small site for my friends where we can create users and edit profiles and comment eachother.
Like a scaled down social network site. The problem is, I really can't get my head around the whole idea of relational databases.

What I have is a table for the users - which stores their username, password etc.
I then want this to link into my profile table, which stores their pictures and page-style information etc.
This could then link into other tables for things like comments or statuses etc.

I am using MySQL and I thought I could link e.g. the user table to the profile table by having the same id. For example, the user table has a user_id field (primary key) and a profile_id which links into the profile_id (primary key) on the profile table.
But I just don't get how to implement this.
It's really hard to explain. I want it, so that when a user registers - not only does the user_id auto increment, but so does the profile_id in the profiles table. And the pictures information and other information from the profile table can be used by the user table to define who the users are etc.

Could anyone please lend me a helping hand with this. I will try and explain more clearly if you would like.

Thank you a lot.

Josh

I don't believe that you need a profile_id, just use the user_id as the key in the profiles table. When you create a new user, insert a record into both tables. When you delete a user's account, delete from both tables.

To access the profile of a user, you can then select * from profiles where user_id = <userId> . To get their user details, replace the word profiles in that statement with users. If you want to see both the user details and the profile for each user, the following simple join can achieve this:

select * from users
inner join profiles
on users.user_id = profiles.user_id

Sick man.
That's actually a really good idea.

I'm going to try it out.
Thank you so much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.