By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

mysql query help pls :O

P: 1
Hi, im working on a pretty basic friends system for a website, so far it is all working but i have a Friends of Friends feature - which works to an extent but because of the way my queries are set out its bringing back duplicate results if 2 or more people you know also have the same friend apart from you, which looks very unprofessional.
I have tried to keep the actual coding simple but i cant work out what to use to stop duplicate outcomes... any advice is apreciated

so far it is set like this:

"friends" database is:
`id` int(11) NOT NULL auto_increment,
`uid` varchar(30) default '', <- user's id relevant to the members db
`fid` varchar(30) default '', <- user's friend's id relevant to the members db

current code:
// get current user's friends

$fquery = mysql_query("SELECT * FROM friends WHERE uid = '$uid'");
while($query1 = mysql_fetch_array($fquery)){
$fid = $query1['fid'];

// get username of this friend

$query2 = mysql_query("SELECT id,username FROM members WHERE id = '$fid'");

$bleh = mysql_fetch_array($query2);
$blehname = $bleh['username'];

// search for this friend's friends - but without returning the current user

$ffquery = mysql_query("SELECT * FROM friends WHERE uid = '$fid' && fid != '$uid'");
while($iid = mysql_fetch_array($ffquery)){
$ffid = $iid['fid'];

$fgetquery = mysql_query("SELECT id,username FROM members WHERE id = '$ffid' LIMIT 30");
$final = mysql_fetch_array($fgetquery);
$ffriendn = $final['username'];

echo '<a href="?profile&uid='.$ffid.'" title="Common friend: '.$blehname.'" class="">'.$ffriendn.'</a> ';

As you can probably see it gets all, but because of way i set it out i cant work out how to stop results being repeated.
Please any pointers would be very helpful.

Thanks, Mark
Aug 31 '05 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.