views:

32

answers:

1
+1  A: 

if i understood you correctly you seem to be creating a new table for each user's friends (1 users table + X tables named the user's name) this isnt a good approach and you'd be better off with just 2 tables: users and user_friends as follows:

drop table if exists users;
create table users
(
user_id int unsigned not null auto_increment primary key,
username varbinary(32) unique not null
)
engine=innodb;

drop table if exists user_friends;
create table user_friends
(
user_id int unsigned not null,
friend_user_id int unsigned not null,
created_date datetime not null,
primary key (user_id, friend_user_id) -- note clustered composite PK (innodb only)
)
engine=innodb;

A full example script can be found here : http://pastie.org/1242699

Hope this helps.

f00
If I will do that, the records will be doubled no? like: 5 is friend with 10 , 10 is friend with 5. Is there a way to prevent this or just leave it that way?
why prevent it, isnt it possible for user 5 to remove his friendship link with 10 because perhaps they dont chat that often anymore but user 10 decides to keep his friendship relation with 5 regardless.
f00