Page 1 of 1

php friend request system help

Posted: Sun Mar 18, 2012 11:50 pm
by Smg
ok since temor has finally helped me make my commenting system work now i need help on a friend request system so if anyone can help me can you give me basic ideas on how to create a friend request system?

Re: php friend request system help

Posted: Tue Mar 20, 2012 10:09 pm
by jacek
I find the database is always a good place to start. So you want a way to store a link between two users. Once way would be to have two columns, one for the users ID and one for the user ID of the friend. Set that up in phpmyadmin first :)

Then you need to work out how to manipulate that from your script, so write out the skeleton of the functions you will probably need

[syntax=php]function is_friend($user_id){

}

function fetch_all_friends(){

}

function add_friend($user_id){

}

function remove_friend($user_id){

}[/syntax]

Start at the top and try to work out what queries you need to run to get the information for each one.

Have a play with the functions on a test page and make sure the results are right, then use them to make the page.

You can always make a more specific post if you get stuck at any point :)

Re: php friend request system help

Posted: Sun Mar 25, 2012 9:10 pm
by Smg
okay I am really sorry but I have done this so far and I am still confused....
its mainly because i'm still learning php at the basics...

here is what i have done so far...
user.inc.php:
i added the code that you gave me.

and for the sql I did this:

user_id & friend_id both with a normal int

i am mainly confused because I did try to do a mysql_query but I don't know how to start it up :\

Re: php friend request system help

Posted: Tue Mar 27, 2012 5:30 pm
by jacek
Could you post what you tried ? Pretty hard to help without knowing the problem :)

Re: php friend request system help

Posted: Fri Mar 30, 2012 11:02 pm
by Smg
ok i was thinking about something like this since it would be easier to do....

first i would make the friends table and do this...
The SQL:
id = auto_increment
user_id = id from the main table representing the user_id of the user

and make a form that submits these into the database

the friend id's from 0 - 3:

if they are not friends = 0
if they are friends = 1
if request not confirmed = 2
if request rejected = 3

for the depending requests on the 0 1 2 3
u can display his or her info.

also tell me if there is anyway to make this better written?
but im confused on how to do this meaning writing the code out....

Re: php friend request system help

Posted: Sat Mar 31, 2012 11:42 pm
by jacek
That could work yeah.

the way I did this was to have a table with 3 columns user_id, friend_id and approved

user_id is the id of the user you are talking about. when they send a friend request to a user you insert a row into the table with the friend_id being the id of the user they sent the request to and 0 for the approved column. then when the friend accepts the request you update the table setting approved to 1.

Obviously friendship is both ways, so if user_id is friends with friend_id then friend_id is also friends with user_id which makes getting a list of a given users friends a little tricky.

Re: php friend request system help

Posted: Tue May 22, 2012 7:38 pm
by roenu
Thank You, jacek, for the startercode. I try to implement it to my website :)

Re: php friend request system help

Posted: Wed May 23, 2012 11:33 pm
by jacek
roenu wrote:Thank You, jacek, for the startercode. I try to implement it to my website :)

No problem :) Good luck ;)