How To Order Lists

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Dream$of$uccess
Forum Newbie
Posts: 3
Joined: Thu Feb 15, 2007 1:47 am

How To Order Lists

Post by Dream$of$uccess »

Hello,

I am creating a website for one of my clients and they are a nationwide organization with about 200 users that will login. They want me to create profiles for the users which is fine, but they want a friends list within the profiles and this is where I came about with the problem.

I want to set it up so that there will be 2 columns in my MySL database, UserId, and Friends.

For the friends column, how do I add it to the column in sequence without overwriting the old things. Or is there a better way for me to do this?

Ive never done this type of project.

Enlighten me :)

James
shwanky
Forum Commoner
Posts: 45
Joined: Thu Feb 15, 2007 1:21 am

Post by shwanky »

I'm not sure I fully comprehend what it is your trying to accomplish. But it sounds like, to me, that you're looking for a table relation between a friends table and the profile table.

The profile table could look something like this

profile_id
profile_firstname
profile_lastname

Your friends table could look like this

profile_id
friend_id

To retrieve all the friends you would do something like

SELECT friend_id FROM friends_table where profile_id='some_id';

Is this sort of what you were looking for?
Dream$of$uccess
Forum Newbie
Posts: 3
Joined: Thu Feb 15, 2007 1:47 am

Post by Dream$of$uccess »

I already have a profile...

Im asking what is the best way to create a friends list in MySQL (that will have new additions all the time)...

The system also needs to be able to be easily post all the seperate friends back in the users profile
shwanky
Forum Commoner
Posts: 45
Joined: Thu Feb 15, 2007 1:21 am

Post by shwanky »

Dream$of$uccess wrote:I already have a profile...

Im asking what is the best way to create a friends list in MySQL (that will have new additions all the time)...

The system also needs to be able to be easily post all the seperate friends back in the users profile
There isn't a "best" way to create a freinds list. It's what ever works. My sample was an idea. If you already have the profile table the create another table that builds has makes a realtion between profiles. In my example profile_id is the id from the profile_id of a specific user and friend_id is another the id of a there selected friend's profile_id.

For example, if my profile_id = 1 and I have friends with profile_ids 5, 6, 7, 8 and 9.
Let P represent my profile_id and F represent my friend's profile_id

P|F
---
1|5
1|6
1|7
1|8
1|9

This is assuming however that the friends are being selected from existing profiles.
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post by Trenchant »

In my mind that would be the best way. For every friend relationship there should be a new row in the database.

The way you suggested in the original post would be very hard to process. Othere then simply listing the users. It would be difficult to work with after that.
Post Reply