contra10 Posted January 13, 2009 Share Posted January 13, 2009 i'm trying to show a friend in common in a search my code so far is as follows <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if(isset($_POST['submit'])) { $postuser = "{$_POST['username']}"; $postcountry = "{$_POST['country']}"; $postfemale = "{$_POST['sexf']}"; $postcountry = "{$_POST['country']}"; $postage1 = "{$_POST['age1']}"; $postage2 = "{$_POST['age2']}"; $query = "SELECT * FROM users WHERE `username` ='$postuser'"; if(isset($_POST['username']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `username` = '$postuser' ";} if(isset($_POST['sexf']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `sex` = '$postfemale' ";} if(isset($_POST['sexm']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `sex` = 'male' ";} if(isset($_POST['age1']) and ($_POST['age2']) and ($_POST['country']) and ($_POST['submit'])){$query .= "and `age` BETWEEN '$postage1' and '$postage2'";} $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $user = "{$row['id']}"; $userq = "{$row['username']}"; $mycountry = "{$row['country']}"; $sex = "{$row['sex']}"; $city = "{$row['city']}"; echo "<TABLE width=800 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; echo "<tr>"; echo "<td width='20%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<br>"; echo "<img src='http://localhost/image/imagereplace.php?id=$user'><br>"; echo "$city, $mycountry $sex</a></FONT></td>"; } $query2 = "SELECT * FROM friends WHERE `username` ='$username' and friendname = '$userq'"; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)){ $bld = "{$row2['fid']}"; echo "<td width='80%'><FONT FACE='ariel' SIZE='2' align='center'><h4>$bld</font></td>"; echo "</tr>"; } ?> } i'm searching for ids in common in my friends table friends table fid userid username friendid friendname Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/ Share on other sites More sharing options...
contra10 Posted January 13, 2009 Author Share Posted January 13, 2009 could i try to get all the friends for each user and echo all similarities <?php echo "<TABLE width=800 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; echo "<tr>"; echo "<td width='20%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<br>"; echo "<img src='http://localhost/image/imagereplace.php?id=$user'><br>"; echo "$city, $mycountry $sex</a></FONT></td>"; } $query2 = "SELECT * FROM friends WHERE `username` ='$username"; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)){ $bld = "{$row2['friendname']}"; } $query3 = "SELECT * FROM friends WHERE `username` ='$userq"; $result3 = mysql_query($query3); while ($row3 = mysql_fetch_assoc($result3)){ $bld3 = "{$row3['friendname']}"; } if ($bld == $bld3){ echo "<td width='80%'><FONT FACE='ariel' SIZE='2' align='center'><h4>$bld</font></td>"; echo "</tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736430 Share on other sites More sharing options...
GingerRobot Posted January 13, 2009 Share Posted January 13, 2009 You're going to have to explain what the problem is as well as posting some code. Is there an error? What happens? What's supposed to happen? Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736457 Share on other sites More sharing options...
contra10 Posted January 13, 2009 Author Share Posted January 13, 2009 kk...im trying to show mutual friends that a person might share with another user... the codes above search for a user and i want to echo the mutual friends as well...I have a friends table set up which echoes all the friends for that user...how can i find mutual friends with the code that is stated above Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736507 Share on other sites More sharing options...
contra10 Posted January 13, 2009 Author Share Posted January 13, 2009 i would have to call both tables for both users and find similarities with friends Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736522 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 $query2 = "SELECT distinct fid, * FROM friends WHERE `username` ='$username' OR `username` = '$userq'"; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)){ $bld = "{$row2['friendname']}"; } That should pull up the common friends Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736525 Share on other sites More sharing options...
contra10 Posted January 13, 2009 Author Share Posted January 13, 2009 ok the common field is coming up... is there a way to have all the common fields echoed...i thought the while statment would do that... this worked for me <?php $query2 = "SELECT DISTINCT * FROM friends WHERE `username` ='$username' OR `username` = '$userq' ORDER BY friendname ASC"; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)){ $bld = "{$row2['friendname']}"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736530 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.