In the code below I am checking if $count_friend = $select_friend_stmt->rowCount();
equates to 0 or 1. Then based on the result, I have an if
statement to determine other elements. What I do not understand is the first child if condition if ($friend_status == 2) {
:
if ( $count_friend == 1 ) {
//echo $count_friend;
if ($friend_status == 2) {
$friend_status_approved;
}
if ($friend_status == 1) {
$friend_status_pending;
}
if (isset($friend_status_approved)) {
$friend_status_button = "Approved";
}
else if (isset($friend_status_pending)) {
$friend_status_button = "Pending";
}
echo var_dump($friend_status) . "*1 - status";
}
Is not running the child if
statements. I think I have narrowed down the issue, but I am unsure of how to fix it. I do not think, if ( $count_friend == 1 ) {
is the issue because under echo var_dump($count_friend) . "Count Friend";
I get the correct integer.
Now, when I go to a user who's $friend_status = 1;
I get the following output from my var_dump()
's
int(1) Count
Friendstring(1) "1"
*1 - statusstring(1) "1"
*0 - status
Is string(1) "1"
causing issues for me?
I have tried doing: if ($friend_status == "1") {
.. and .. if ($friend_status == '1') {
, but it did not help.
My status
column is configured in my database like the following:
status
enum('0','1','2') COLLATE utf8_unicode_ci DEFAULT '0'
Any ideas why my code is not producing results for my if ($friend_status
's?
$okay = true;
$friend_status_button = null;
$profile_viewer_message = null;
//Checking to see if $user_id and $profile_user IS listed to allow $friend_status conditions to work for them below
$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);
$count_friend = $select_friend_stmt->rowCount();
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'];
}
//Query to check if a friend request was sent
//checking occurrence in db
if ( $count_friend === 1 ) {
//echo $count_friend;
if ($friend_status === 2) {
$friend_status_approved = true;
}
if ($friend_status === 1) {
$friend_status_pending = true;
}
if (isset($friend_status_approved)) {
$friend_status_button = "Approved";
}
if (isset($friend_status_pending)) {
$friend_status_button = "Pending";
}
//echo var_dump($friend_status) . "*1 - status";
}
else if ( $count_friend === 0 ) {
$friend_status = 0;
$select_friend_2 = 0;
if ( $user_id == $profile_user ) {
$friend_status_my_profile = true;
}
else if ($friend_status == $select_friend_2) {
$friend_status_norelate = true;
}
if (isset($friend_status_my_profile)) {
$friend_status_button = "";
$profile_viewer_message = "This is your profile.";
}
if (isset($friend_status_norelate)) {
$friend_status_button = '<div id="add-friend"><img src="../icons/collection/add.png" alt="Add Friend">' . "Add Friend" . '</div>';
}
}
else {
echo "Friend Status not found.";
}