•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 423,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,181 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser: Programming Forums
Views: 1493 | Replies: 1
![]() |
•
•
Join Date: Aug 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I am building a site for which I would like to add a "friends" invitation system. Once member invites another to be a friend, the second member has to accept to become friends. So both members have to agree to be friends.
My problem is that I can't think of a db schema that will allow me to do this without being redundant or requiring multipe requests to get a list of friends.
This is what I've come up with so far:
Table: Users
- userID
- (etc)
Table: Friends
- fromID
- toID
So if user1 invites user2, there is an entry in Friends where fromID=user1 and toID=user2. When user2 accepts, an entry is added to Friends where fromID=user2 and toID=user2. Now that they've both "invited" each other, they are friends. But now I have two rows for every friend relationship and have to do two queries to see who user1's friends are.
I'm a decent programmer and a good UI designer, but a novice db designer at best. I could use some recommendations. Thanks.
My problem is that I can't think of a db schema that will allow me to do this without being redundant or requiring multipe requests to get a list of friends.
This is what I've come up with so far:
Table: Users
- userID
- (etc)
Table: Friends
- fromID
- toID
So if user1 invites user2, there is an entry in Friends where fromID=user1 and toID=user2. When user2 accepts, an entry is added to Friends where fromID=user2 and toID=user2. Now that they've both "invited" each other, they are friends. But now I have two rows for every friend relationship and have to do two queries to see who user1's friends are.
I'm a decent programmer and a good UI designer, but a novice db designer at best. I could use some recommendations. Thanks.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Database Design Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsl adsl1 adsl2 adsl2+ avatar backup breach cable connection creative daniweb data protection database design engineering government hacker howto ibm illustrator internet kb kbps linux mbit medicine mmorpg network news normalization per persuade photoshop pirate print second security server social software sql survey terrorism toread tutorials upload web windows xp workgroup 240000
- Best way to build a LAN? (Networking Hardware Configuration)
- Problem about Bus Topology (Networking Hardware Configuration)
- Transfering info from old-new with XP (Windows NT / 2000 / XP / 2003)
- Final Year Project (Networking Hardware Configuration)
- firewalls? (Networking Hardware Configuration)
- network settings for a game (Networking Hardware Configuration)
Other Threads in the Database Design Forum
- Previous Thread: help me on blog Dtabase
- Next Thread: SQL Query Analyzer Problem


Linear Mode