I got a really big problem which I can't seem to solve. However, I'm not really a genius in coding. So, I am trying to code kind of a Social Networking Site. OK, I have a Database called friends_real with two columns.
friends_real
own_name friend_name
patrick philip
philip george
george lennie
lennie patrick
kurt philip
patrick kurt
bob george
(just as an example right now)
This is kind of a who is a friend with whom thingy. Let's focuse on patrick (highlighted in blue) As seen patrick is friend with: philip, lennie and kurt.
Now I want to output on my site with whom MY friends philip, lennie and kurt are friends with. So, if the code works it should ouput:
philip is a friend with patrick
philip is a friend with george
philip is a friend with kurt
lennie is a friend with patrick
lennie is a friend with george
kurt is a friend with philip
kurt is a friend with patrick
(I hope i got it right)
I mean I kind of got the idea how to do it, but I am still failing. Below there is one of my tries, it is probably more complicated than it has to be and it still doesn't work and things are failing, but it is a try.
$username is the user who is logged in! (in our example patrick)
Code: Select all
$query = mysql_query ("SELECT * from friends_real where own_name = '$username' OR friend_name = '$username';");
echo "News-Feed:<p>";
while ($output_mysql = mysql_fetch_assoc ($query))
{
if ($output_mysql['own_name'] == "$username")
{
$query_1 = mysql_query ("SELECT * from friends_real where friend_name = '$output_mysql[friend_name]';");
while ($query_2 = mysql_fetch_assoc ($query_1))
{
echo $query_2['own_name'] . " is now a friend with " . $query_2['friend_name'] . "<p>";
}
}
else
{
$query_7 = mysql_query ("SELECT * from friends_real where own_name = '$output_mysql[own_name]';");
while ($query_8 = mysql_fetch_assoc ($query_7))
{
echo $query_8['own_name'] . " is now a friend with " . $query_8['friend_name'] . "<p>";
}
}
}
Thanks a lot!