Jump to content

friends in common


contra10

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/140703-friends-in-common/
Share on other sites

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>";
	}
?>

Link to comment
https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736430
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736507
Share on other sites

   $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

Link to comment
https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736525
Share on other sites

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']}";
   }

?>

Link to comment
https://forums.phpfreaks.com/topic/140703-friends-in-common/#findComment-736530
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.