In the code below I 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 if condition:
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?
$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();
$friend_status_button = null;
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'];
}
echo var_dump($count_friend) . "Count Friend";
//else if ( $count_friend == 1 || $count_friend == 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";
}
else if ( $count_friend == 0 ) {
$friend_status = 0;
$select_friend_2 = 0;
if ($friend_status == $select_friend_2) {
$friend_status_my_profile;
}
if (isset($friend_status_my_profile)) {
$friend_status_button = "";
}
}
else {
echo "Friend Status not found.";
}
echo var_dump($friend_status) . "*0 - status";
Aucun commentaire:
Enregistrer un commentaire