PDA

View Full Version : Friend System help


Cascade
08-08-2009, 06:35 PM
Hello all!

I am developing a Social Networking Site I am now trying to work out a theory for my friend system I know there are a couple ways to do this. I'd like to get some help with this before I do tons of code an then find out that there was a easier way to do it.

Anyway how my theory in this would work is pretty simple. As most of you probably already know my site has a database which looks something like this.

------------------------------------------------
|UserId|Email|Country|ZipCode|AboutMe|Friends|
------------------------------------------------
basically this database is pretty simple. Now what I'd like to do with the friends table is something like this.

---------
|Friends|[2223232, 556543a, 990as, 334rr5, 889at]

Basically everytime you add a new friend it places the frienduserid into the friend table it would be inorder from things like top friends, then the rest. But I am unsure how this would work.

so if someone could help I'd be very happy :)

edbr
08-09-2009, 12:32 AM
i would maybe usea freids table with fields user_id, friend_id and level,
then select by userid and friend_id order by level.
uou could make level default at say 2 and update to 1 when nominated best buddy

Cascade
08-09-2009, 12:36 AM
reason I don't really want to do it like that is I feel it's a waste of space to have to redo a new row an feild everytime the same user makes a new friend so like it would look like this then

userid friendid topfriends
[223990] [3330a] [0]
[3330a] [223990] [0]
[228990] [4450a] [1]
[4450a] [228990] [0]

I just feel it's almost a waste of space.
If you understand any of what I am trying to show.

bee80
08-09-2009, 09:25 AM
its not a waste of space its called normalization , breaking the tables down in to the smallest useable data i.e atomic data. I would use something like edbr mentioned.
p.s you shouldnt have to redo a new row everytime someone makes a new friend your code should do it for you.

bee80
08-09-2009, 09:30 AM
also i would have a user table with |userId|email|country|zip|
then a profile table with |profileId|userId|aboutMe|activities|interests|
then the friend table |userId|friendId|level|
keeping all relevant data in its own table will speed up queries

Cascade
08-09-2009, 03:26 PM
I always thought it would take longer to query the database with something like that?

Reason I think that is look at it this way.

if I have 1000 users that has more then 40 friends then I have to go through tons of data to find every single one of your friends. Which would take a little longer then it would if all the data was in one row. But I get where your coming from.

bee80
08-09-2009, 08:40 PM
if you put friends in with the user table you would have to repeat :
|UserId|Email|Country|ZipCode|AboutMe|Friends|
for every 1 friend you added for example:
|1|me@home.com|uk|LN1 3HG|i am tall|John|
|1|me@home.com|uk|LN1 3HG|i am tall|Peter|
|1|me@home.com|uk|LN1 3HG|i am tall|Paul|

where as the friend table work as

|userid|friendsid|level|

|1|1|0|
|1|2|0|
|1|7|1|

Cascade
08-10-2009, 12:11 AM
You missunderstood what I was saying the friends list is just another field in user it has nothing to do with userid or about me or email or any of the other stuff.

edbr
08-10-2009, 12:57 AM
why? if you use the same table you will be adding extra rows the idea i suggested and bee alaborated on uses a seperate table and is the normal way to do a thing like this as far as i know, or am i not getting your point?

Cascade
08-10-2009, 02:14 AM
Well my plan which probably wont be used now. Was something like this.

userid email country zipcode friends
3234 me@web.com USA 22342 2231412, 990011, 002323

Basicly you would not have to remake new rows or collums for new friends it would just simply add onto the collum of friends, but I now see that this could be time consuming an a lot more coding then worth so I've decied to go a differnt way with this.

Thanks to all for the ideas an support :)

bee80
08-10-2009, 05:59 PM
i dont think anyone would recommend doing it that way, it would be too difficult to break up because when you queried the friend column it would simply send back 22342 2231412, 990011, 002323!! then how would you seperate them?

Cascade
08-10-2009, 07:16 PM
Thanks I got it all figured out how I will do it :)

I have a quick question I keep on getting a parse error when I run my test enviroment I get

Parse error: C:\wamp\www\Actions\login.php line 23

on line 23 is this.

header("location:home.php");

I've tried

header('location:home.php');

header['location:home.php'];

header["location:home.pph"];

so I dunno what I did wrong = /

bee80
08-10-2009, 08:07 PM
check line 22 and before sounds like you forgot to close something or forgot a semi colon

Cascade
08-10-2009, 08:38 PM
line 22 is

$_SESSION['id'] = $rowaccount['user_id'];

I don't think there is anything wrong with it.

edbr
08-11-2009, 12:45 AM
try an absolute
header["location:http://www.domain.com/home.php (http://www.your-domain.com/home.pph)"];

Cascade
08-11-2009, 12:46 AM
Alrighty then