php friend request system help

Ask about a PHP problem here.
Post Reply
Smg
Posts: 30
Joined: Tue Feb 21, 2012 2:38 am

php friend request system help

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: php friend request system help

Post 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 :)
Image
Smg
Posts: 30
Joined: Tue Feb 21, 2012 2:38 am

Re: php friend request system help

Post 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 :\
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: php friend request system help

Post by jacek »

Could you post what you tried ? Pretty hard to help without knowing the problem :)
Image
Smg
Posts: 30
Joined: Tue Feb 21, 2012 2:38 am

Re: php friend request system help

Post 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....
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: php friend request system help

Post 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.
Image
roenu
Posts: 1
Joined: Tue May 22, 2012 7:31 pm

Re: php friend request system help

Post by roenu »

Thank You, jacek, for the startercode. I try to implement it to my website :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: php friend request system help

Post by jacek »

roenu wrote:Thank You, jacek, for the startercode. I try to implement it to my website :)

No problem :) Good luck ;)
Image
Post Reply