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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.