mysql query help pls :O

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mlw
    New Member
    • Aug 2005
    • 1

    mysql query help pls :O

    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
    PRIMARY KEY (`id`)

    current code:
    [PHP]
    // get current user's friends

    $fquery = mysql_query("SE LECT * FROM friends WHERE uid = '$uid'");
    while($query1 = mysql_fetch_arr ay($fquery)){
    $fid = $query1['fid'];

    // get username of this friend

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

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

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

    $ffquery = mysql_query("SE LECT * FROM friends WHERE uid = '$fid' && fid != '$uid'");
    while($iid = mysql_fetch_arr ay($ffquery)){
    $ffid = $iid['fid'];

    $fgetquery = mysql_query("SE LECT id,username FROM members WHERE id = '$ffid' LIMIT 30");
    $final = mysql_fetch_arr ay($fgetquery);
    $ffriendn = $final['username'];

    echo '<a href="?profile& uid='.$ffid.'" title="Common friend: '.$blehname.'" class="">'.$ffr iendn.'</a> ';
    }}[/PHP]


    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
Working...