Link to home
Start Free TrialLog in
Avatar of helpchrisplz
helpchrisplz

asked on

friend request and show active friends php

i made a working friend request system but it breaks if two users add the same person. :S

its showing users that have been activated for the current memberID in the output of my query
i just put id's of users in both ways in the table when some one wants to add a friend.
but if 2 users add the same person that persons id will show in two rows and my query cant handle that so am trying to fix it so it doesn't have that problem .

the code i am shoing is the bit that checks if the user (when on there profile) has any friends activated and if so show them

 
<?php
	$friendPlayerName = "Player Name: <br>";
$Email = "Players Email: <br>";
$title = "Your Accepted Friends: <br>";

	include("conf.php");
       
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");
	
$sqlf = "SELECT friends.friendPage FROM friends 
WHERE friends.activate = '1' AND friends.friendID = '".$_SESSION['MemberID']."'";


$resultf = mysql_query($sqlf)or die(mysql_error());

while($row = mysql_fetch_array($resultf, MYSQL_ASSOC))
{
	$friendPage = $row['friendPage'];//now i can compare this with current log in user later on

}


//where current member id = friendPage and friendId = $friendPage

$sqlfTwo = "SELECT friends.friendID,friends.playername,friends.UserEmail,images.imgSmall FROM friends JOIN images ON images.memberId = friends.friendID 
WHERE friends.activate = '1' AND friendID = '$friendPage'";
$resultfTwo = mysql_query($sqlfTwo)or die(mysql_error());

while($row = mysql_fetch_array($resultfTwo, MYSQL_ASSOC))
{
	

echo '<img src='. $row['imgSmall'].'><br>';
echo '<a href="users.php?id='. $row['friendID']. '">' . $row['playername'] . '</a><br>';
echo $row['UserEmail'].'<br><br>'; 

}

mysql_close($connection);

Open in new window

CREATE TABLE IF NOT EXISTS `friends` (
  `id` int(11) NOT NULL auto_increment,
  `friendID` varchar(50) NOT NULL,
  `UserName` varchar(55) NOT NULL,
  `friendPage` varchar(55) NOT NULL,
  `playername` varchar(55) NOT NULL,
  `activate` varchar(55) NOT NULL,
  `UserEmail` varchar(55) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `friends`
--

INSERT INTO `friends` (`id`, `friendID`, `UserName`, `friendPage`, `playername`, `activate`, `UserEmail`) VALUES
(1, '2', '', '1', 'chris', '1', 'chris@chris.com'),
(2, '1', '', '2', 'admin', '1', 'admin@admin.com'),
(3, '4', '', '1', 'ben', '1', 'ben@ben.com'),
(4, '1', '', '4', 'admin', '1', 'admin@admin.com');

Open in new window


id ,      
friendID = id of session or id of friend (i put this in both ways),
UserName = not using      
friendPage = id of session or id of friend (i put this in both ways),       
ASKER CERTIFIED SOLUTION
Avatar of palanee83
palanee83
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of helpchrisplz
helpchrisplz

ASKER

ok i have them tables up now

do i just put the users in both ways when one adds?

INSERT INTO friends(UserID, friendID) VALUES ('$UserID', '$friendID');

INSERT INTO friends(friendID, UserID) VALUES ('$friendID', '$UserID');


hmmm my problem was more complicated than i expected
lots of other stuff that was not working but yes