---------------------------
| Friends |
---------------------------
| Friend1 | Friend2 |
| 6 | 78 |
| 6 | 7 |
| 23 | 6 |
| |
---------------------------
My code:
CODE
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/Scripts/PHP/DB.inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/Scripts/PHP/Class/Profile.class.php");
error_reporting(E_ALL);
$Connect = ConnectDB();
$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$Query = $Connect->prepare("SELECT * FROM Friends WHERE Friend1 = :F1 OR Friend2 = :F1 AND Accepted = :ID");
$Query->bindValue(":ID", "1");
$Query->bindValue(":F1", $_SESSION['ID']);
$Query->execute() or die("FAILED");
$Results = $Query->fetchAll();
$Pending = $Connect->prepare("SELECT * FROM Friends WHERE Accepted = :ID AND Friend1 = :F1");
$Pending->bindValue(":F1", $_SESSION['ID']);
$Pending->bindValue(":ID", "0");
$Pending->execute() or die("Error");
$Results2 = $Pending->fetchAll();
echo("<div id='Content'>". PHP_EOL . "<h2><b>Friends (". count($Results) .")</b></h2><br>");
foreach($Results as $Rows){
$Class = new Profile($Rows['Friend2']);
$FullName = $Class->getUserData("FullName");
$Class = new Profile($Rows['Friend1']);
$FullName2 = $Class->getUserData("FullName");
echo <<<HTML
<a href="/Profile?ID={$Rows['Friend2']}">{$FullName}</a><br>
<a href="/Profile?ID={$Rows['Friend1']}">{$FullName2}</a><br>
HTML;
}
echo("<br><b>Pending Friends (". count($Results2) .")</b><a href='/Notifications'> Manage Requests here</a>");
echo("</div>");
Basically Friend1 is the sender. In this case the current user is '6', 6 isn't always the sender sometimes he's the receiver. Now to include those friends, in the case where he is the receiver, it will echo his name along with the others. How should I fix this? Thanks!