DISPLAY NUMBER OF FOLLOWERS

On my website, all of my users are on a repeating layout. I have a “follow” button on the repeating layout so that users can follow each other. This is the code I used:

});

import wixUsers from “wix-users”;
import wixData from “wix-data”;
export function button20_click() {
const followerId = wixUsers.currentUser.id;
console.log(“followerId: “, followerId);
const followeeId = $w(”#dataset1”).getCurrentItem()._owner;
console.log("followeeId: ", followeeId);
wixData.insert(“Followers_Followees”, {
“followee”: followeeId,
“follower”: followerId
}) .catch((err) => {
console.log(err);
});
}

Is there a way to display the number of users following other users? I would like to have a number next to each follow button that shows how many users are following. Thanks in advance to anyone who helps out!

-Pawtalog

1 Like

There are two ‘following’ things:

  1. how many this user is following others (following)
  2. how many users are following this users (followers)

Which of the two do you want?

I want “2”, how many users are following this user.
Also, here is a link to the page on my website where I want the “follow” buttons: https://www.pawtalog.com/profiles

OK, so I assume that, when the above is finished, nothing should happen there. Something should happen when the other user logs on, goes to his profile page and then his followers are shown.
On this page, do a simple query on the followier-followee collection using .count. Look here:https://www.wix.com/code/reference/wix-data.WixDataQuery.html
And then you display that number.

There is also another way: in the code that you have shown, add a field “numberOfFollowers” ,open the followee profile collection in the above code, increment the number by 1 and update it. That way, you do not consume as many cycles for a query. This is actually how it is done, this type of DB is built for it, taking for granted that it really does not matter if the amount of followers displays 1179 or 1181.

Hi,
I am having trouble understanding how to display the number of followers. How can I do this? I’m new to Wix Code, so simpler instructions would be appreciated. Thanks!

1 Like