I am trying to run and if/if else statement so that if the current logged in user's id is not in the database columns: friend_one AND friend_one that I can set the $friend_status to zero, but if friend_one AND friend_two have a relationship, the else if statement will run.
I cannot figure out if I am doing the if statements for the queries correctly. I do not know if I am setting the conditions the right way.
Any help appreciated
Now to the code:
if ( $friend_sql = "
SELECT friend_one, friend_two
FROM friends
WHERE friend_one AND friend_two IN(:userid, :profile_user) = NULL
"
) {
$select_friend_stmt = $con->prepare($friend_sql);
$select_friend_stmt->execute(array(':userid' => $user_id, ':profile_user' => $profile_user));
$friend_rows = $select_friend_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($friend_rows as $friend_row) {
$select_friend_1 = $friend_row['friend_one'];
$select_friend_2 = $friend_row['friend_two'];
$friend_status = $friend_row['status'];
$friend_status_date = $friend_row['date'];
}
} else if (
$friend_sql = "
SELECT *
FROM friends
WHERE friend_one = ?
AND friend_two = ?
"
) {
$select_friend_stmt = $con->prepare($friend_sql);
$select_friend_stmt->execute(array($user_id, $profile_user));
$friend_rows = $select_friend_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($friend_rows as $friend_row) {
$select_friend_1 = $friend_row['friend_one'];
$select_friend_2 = $friend_row['friend_two'];
$friend_status = $friend_row['status'];
$friend_status_date = $friend_row['date'];
}
}
else {
echo "Friend Status not found.";
}
if ($friend_status == 2) {
$friend_status_approved;
}
if ($friend_status == 1) {
$friend_status_pending;
}
if ($friend_status == $select_friend_2) {
$friend_status_my_profile;
}
$friend_status_button = null;
if (isset($friend_status_approved)) {
$friend_status_button = "Approved";
}
else if (isset($friend_status_pending)) {
$friend_status_button = "Pending";
}
else if (isset($friend_status_my_profile)) {
$friend_status_button = null;
}
else {
$friend_status_button = "Add Friend";
}
Aucun commentaire:
Enregistrer un commentaire