I have a database where i take registrations from my clients through input and data submits to database with the help of submit button i just want to show how many peoples registered Live Count
Hello rahul,
you need something like this…?
https://russian-dima.wixsite.com/wixworld/blank-6
It’s not working perfect, so you have still to work on it.
It’s just an example.
Do you access db thru wx-dataset or wx-data?
Wix dataset … wht i have did is !!
i Made a dataset and create a form with the help of inputs and i want to show my visitors that how many of peoples registered so far so that they could make their mind to get registered … i just want to show live count of registered users who successfully submitted registration
Hello rahul,
- if you want to know how much registred user your site already has, you have to enter the “PrivateMembersData” and this code might be a solution for your issue…
import wixData from 'wix-data';
$w.onReady(function () {getRegistered_MEMBER()});
function getRegistered_MEMBER (parameter) {
wixData.query("Members/PrivateMembersData")
.find()
.then((res) => {
console.log(res)
let myFirstItem = res.items[0]
console.log(myFirstItem)
let MembersCount = res.length
console.log(MembersCount)
})
}
Just take a look into your CONSOLE-LOG in your Browser (F-12 when using google-Chrome).
The “MembersCount”-value should give you the count of your registrated members.
ATTENTION!!! But there is a problem, because you are not allowed to enter the MembersCollection if you are not logged-in.
That means this function is without effect, because it will show nothing to unregistered user, because they are not logged in.
But, if there is a way to byPass the permissions to enter the PrivateMembers-Database, so perhaps it could be the solution.
EDIT: I just have found an article written by “Ahmad”, which could help to realize this problem, look here…
- If you use your OWN-MEMBER-DATABASE, so i see no problems to realize your wishes.
I am facing same issue can you share the code .
Hey there …
Using the article that @russian-dima mentioned, use a backend web module to bypass the private members permissions.
// Backend: members.jsw;
import wixData from 'wix-data';
// Options to bypass the permissions.
const options = { suppressAuth: true }
export function getTotalMembersCount() {
return wixData.query('Members/PrivateMembersData').find(options).then((x) => {
return x.totalCount;
})
}
Notice that I used the totalCount, not the length, the length is the amount of results returned from the query, which is by default (50), and can be up to 100 for Wix collections, and 1000 for custom collections.
While the totalCount returned the total number of items in the database that matches the query criteria, and since we have no refinements, the number of all members is returned.
Now it’s just a matter of calling the function on your page and display the result.
import { getTotalMembersCount } from 'backend/members.jsw';
$w.onReady(() => {
getTotalMembersCount().then((totalNumber) => {
$w('#total').text = `Registered Members: ${totalNumber}`;
})
})
Oh! And by the way @russian-dima, this collection is “Admin” only, that means no one except the admins can access it, even the logged in members.
Hope this helps~!
Ahmad
Thanks! Yes you are surely right, this is an very old example of my very beginning time. I will replaces this example soon with another one .
It’s like a time-travel for me, when i see my old posts xDDDDDDDD😆
Anyway, i have gather new information from your good described examples (like always)
@russian-dima glad that it was useful