I am creating a social network, I need to show the user how many people they follow and how many people follow them(followers and following). I want to add up the values in the user_to
and user_from
where the current user logged in is the person who followed someone or received a follow.
I am using this code below:
$user_follow_query = $con->prepare('SELECT SUM(user_to) FROM following WHERE user_to = ?');
$user_follow_query->bind_param("s", $username);
$user_follow_query->execute();
$user_follow_query->bind_result($followers);
$user_follow_query_result = $user_follow_query->get_result();
while ($row = $user_follow_query_result->fetch_assoc()) {
$followers = $row['user_to'];
}
But I'm getting this error:
( ! ) Notice: Undefined index: user_to in C:\wamp64\www\theshow\profile.php on line 38
On this line:
$followers = $row['user_to'];
Any help ?