+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP - Help With Friends System

  1. #1
    masterjake is offline x10Hosting Member masterjake is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    73

    PHP - Help With Friends System

    Does anyone know how to do a friends system. This is how I was going to setup mine but doing it this way I will need a little help.

    When you add a friend it updates a database entry with your friends and adds exactly this "#friend,". I do it this way because some people have spaces in there name but no one has a # in their name as its forbidden in my registration script. Now when the time comes to view there friends I need it to go into that entry, break up all of the friends removing the #'s and ,'s and then add them into an array so I can do sql querys on the array and get the id of each friend so I can put a link to their profiles on the view friends page. Can someone help?

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP - Help With Friends System

    First, use an auto_increment integer for a unique key for each user. This is called the primary key and is used to link rows to each other.

    To create a friend list, simple create your user table and then create a friend table with columns userID and friendID. Place the users ID number (that is, the one that is created through auto_increment) in userID and the friends ID number in friendID. And there you go. One friend list
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  3. #3
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: PHP - Help With Friends System

    Quote Originally Posted by masterjake View Post
    Does anyone know how to do a friends system. This is how I was going to setup mine but doing it this way I will need a little help.

    When you add a friend it updates a database entry with your friends and adds exactly this "#friend,". I do it this way because some people have spaces in there name but no one has a # in their name as its forbidden in my registration script. Now when the time comes to view there friends I need it to go into that entry, break up all of the friends removing the #'s and ,'s and then add them into an array so I can do sql querys on the array and get the id of each friend so I can put a link to their profiles on the view friends page. Can someone help?
    xmakina is right - the array system is too cumbersome.

    When you want to show all the friends for the user signed in, you just create a recordset where the userid == the uniqueid of the person logged in.

  4. #4
    masterjake is offline x10Hosting Member masterjake is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    73

    Re: PHP - Help With Friends System

    Yeah but I don't want to create an individual table for each user, that get's too annoying and large to keep up with, i'd rather do the arrays.

  5. #5
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: PHP - Help With Friends System

    Quote Originally Posted by masterjake View Post
    Yeah but I don't want to create an individual table for each user, that get's too annoying and large to keep up with, i'd rather do the arrays.
    You don't need to - all you need is one friends table - the links between your existing user table and the friends table will do the work for you.

    When you click on add friend, you simply insert a record to the friends table, carrying the unique ID from the user table for the logged in user and the unique ID of the "friend".

    recordset:

    SELECT * FROM FRIENDS WHERE LINKUSERID LIKE $_SESSION['userid']

    This will show all friends for the selected user. (based on session but can be from a link or post.)

  6. #6
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP - Help With Friends System

    SELECT * FROM FRIENDS WHERE LINKUSERID = $_SESSION['userid']

    We're dealing with numbers and don't want to risk user 1 getting user 11's friends.

    And Jake, I highly recommend you read up on some database theory before plunging into something like this. You don't sound very clued up on how a database should be structured and organised and without those critical foundations your structure will quickly tumble down.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  7. #7
    masterjake is offline x10Hosting Member masterjake is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    73

    Re: PHP - Help With Friends System

    Naww its cool ;] thanks for the replies I've been using DB's quite a well I understand what they mean by the friends table now.

  8. #8
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: PHP - Help With Friends System

    [quote=xmakina;497303]SELECT * FROM FRIENDS WHERE LINKUSERID = $_SESSION['userid']

    We're dealing with numbers and don't want to risk user 1 getting user 11's friends.
    quote]

    Interesting - I thought this was comparing two absolute values ??

    I obviously need to read up more on numbers.. ;)

  9. #9
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: PHP - Help With Friends System

    Quote Originally Posted by freecrm View Post

    Interesting - I thought this was comparing two absolute values ??

    I obviously need to read up more on numbers.. ;)
    He is; read the post above his.

    SELECT * FROM FRIENDS WHERE LINKUSERID LIKE $_SESSION['userid']
    He changed Like to =; like would match 1 to 1, 11, 111, 1111, and if I'm not mistaken numbers like 1245 as well. = makes it absolute like you pointed out, which is what we needed
    Last edited by Livewire; 12-08-2008 at 07:10 AM.


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  10. #10
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP - Help With Friends System

    It's not so much that it *DOES* match 1 to 11, 111, 1111 and so on as it *MIGHT*. Sure in MySQL it doesn't because it uses wildcards and symbols (e.g. LIKE '1*'), but who knows what variations of SQL will come along. One might think the use of LIKE means *STRING* and therefore 1 will match 1, 12, 113, etc etc.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. PHP and new accounts
    By idani in forum Free Hosting
    Replies: 1
    Last Post: 09-21-2008, 01:49 PM
  3. SUHOSIN - Use of eval is forbidden
    By MaestroFX1 in forum Free Hosting
    Replies: 19
    Last Post: 03-07-2008, 02:42 AM
  4. php problem
    By himgar in forum Free Hosting
    Replies: 1
    Last Post: 02-22-2008, 02:41 AM
  5. Important PHP Information
    By Bryon in forum News and Announcements
    Replies: 0
    Last Post: 11-21-2007, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers