Results 1 to 3 of 3

 

Thread: JOIN command to stop adding duplicate fields (php & mysql)

  1. #1
    This is the one

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    2,882
    Thanks
    29
    Thanked 9 Times in 7 Posts


    Yep, I have yet another problem
    I have a database that has the following userid, frienduserid, friendusername in it (although friendusername probably doesn't really need to be there)

    What happens is that a user (userid) can add another user as their friend.
    So this means any user can add any other user to their friends list.
    When a user clicks on the "add friend" link on my site the details are updated with the "new friend partnership". What I am having problems with is that a user can add the samne friend as many times as they want, so what I need is that if a user alreday has a friendship then if they try to add another then it doesn't get added.

    I've been messing aroudn tryign to get a JOIN working so it works correctly but I just can't seem to get the thing working

    This is what I have it as at the moment (obviously wrong)
    PHP Code:
        $query  "SELECT * FROM friends LEFT JOIN `players` ON friends.frienduserid = players.userid WHERE friends.userid='$frienduserid2' AND friends.frienduserid='$friend2'";          
        
    $result mysql_query($query) or die("Error: " mysql_error()); 

        if(
    mysql_num_rows($result) == 1){ 
            echo(
    "There is already a friendship request"); 
    Can anyone help please (if I have made it clear enough anyway)?

    Cheers
    Wardy

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    2,448
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't really see why you need the join. Isn't it just a case of select from friends where userid is this users id and frienduserid is the id of the person they are trying to add?

    Current you seem to be comparing userid to the $frienduserid2 rather than the current users id - it might just be a case of a badly named variable.

  3. #3
    This is the one

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    2,882
    Thanks
    29
    Thanked 9 Times in 7 Posts
    Rich you are indeed right. The reason I was trying to get more complicated than I needed to was someone suggested it.
    I also forgot to delete all the duplicate enteries I had for each friendship request so it wasn't just matching 1 with the freinds I was testing it on, d'oh
    At least the afternoons work has now been sorted, even though it shoudl of taken 5 mins

    Cheers
    Wardy



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Best PHP & MySQL
    By Stellar in forum Programming
    Replies: 13
    Last Post: 28-07-06, 04:27 PM
  2. Anyone anygood with xml, php, mysql and Affiliate Window
    By AnnonnyMouse in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 23-09-04, 11:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2