Count and Display number of imputs from DB

Hello hackermans :wink: Need quck fix if possible.
I want to count how many users submited input elements form to database and than I want to display it at the regular page. User input elements will show in database in one row, if I have try submitions I will have three rows, and I want to display number 3 at the page.

If someone can helf I would be greatfull :slight_smile:

The error on the last line is because you don’t have matched brackets/parentheses.

The .eq() filter should use the Field Key and not the Field name.

Not this:
.eq(“Kategorija”, “Stojeca pipa”);
This is what you want:
.eq(“kategorija”, “Stojeca pipa”);

To find the Field Key:

Dear Yisrael,

thank you very much for your help. I have changed Field name to Field key, but I’m still not able to find mistake (last row).

@igormatanovic032 Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

@yisrael-wix https://editor.wix.com/html/editor/web/renderer/edit/5cd2beae-419a-4351-8a7a-91cebe66e3c2?metaSiteId=fe54fb80-9891-4c9f-b9a4-88ecff1ce3ae&editorSessionId=935cbcfc-d08f-4aad-9310-d7c366a7ee0c&referralInfo=dashboard

Dear Yisrael, the Page name I want to display database inputs (rows) in number format is ‘Aktivni poslovi’ within Member pages.

Thanks a lot

@igormatanovic032 The Aktivni poslovi page does not have the code that you posted above.

@yisrael-wix Sorry. It has now.

@igormatanovic032 You are missing }) in the code. The last two lines of the code should be:

})
});

@yisrael-wix Oh, I see. Thanks a lot. But I’m still not able to manage displaying it in number format. It shows text.

@igormatanovic032 In order to assist, you need to provide more information. What field? What text is it showing?

Please understand that without the proper information there is no way to know what you are trying to accomplish.

@yisrael-wix In my DB collection ‘User_inputs’ im collecting submited forms from my users. Every form is collected in one row with different cattegory name (‘Kategorija’). For example, someone submited form ‘Stojeća pipa’. So, I want to count how many times someone submited ‘Stojeća pipa’ in my DB and display it as a number in my page ‘Aktivni poslovi’.
If i have three entries of Stojeća pipa in my DB collection, I want no. 3 displayed in tex box on my regular page.


Im not surre did I make right code, I found it at forum for someone asking for similar or same proble. I really apprisiate your help and it would be awesome if you could make tkat work.

@igormatanovic032 You are using the field totalCount:
let totalCount = results.totalCount;
but this field does not exist in the User_inputs collection.

If all you are trying to do is to see how many times a category record appears in the collection, you can use the .count() function, something like this:

wixData.query("User inputs")
   .eq("kategorija", "Stojeća pipa")
   .count()
   .then((num) => {
      $w('#TextCount').text = '' + num;
   })
   .catch((error) => {
      let errorMsg = error.message;
      let code = error.code;
   });

See the .count() API documentation for more details.

Good luck

@yisrael-wix Once again, tkanks for your time, I’m not feeling confortable to bother you any more. It still doesnt work, I guess I’m doing something wron. Will try to learn more about this.

Best regards,
Igor

@yisrael-wix Hey, sorry…it does working…You missed _ in DB collection name ‘User_inputs’ instead of ‘User inputs’.
Thanks a lot. Once again appologies for previous comment.

Have a good one

@igormatanovic032 :tada: :tada: :tada: Yay! Glad you got it working!

@yisrael-wix Thanks for all the help you provide on this platform!

@yisrael-wix Hi Yisrael, what if we want to count the entire array of data in the database using the code below?

wixData.query(“User inputs”)
.eq(“kategorija”, “Stojeća pipa”)
.count()
.then((num) => {
$w(‘#TextCount’).text = ‘’ + num;
})
. catch ((error) => {
let errorMsg = error.message;
let code = error.code;
});

I realized you posted this code in another page;

$w(“#text1”).text = “” + dataArray.length;

How can we combine this to count the entire array of data?

Got it!

import wixData from ‘wix-data’;
wixData.query(“Docudtatabase”)
.count()
.then((num) => {
$w(‘#TextCount’).text = ‘’ + num;
})
. catch ((error) => {
let errorMsg = error.message;
let code = error.code;
});

I want to count the total of rows.
But it’s always 0

this is my code;

import wixData from ‘wix-data’ ;

wixData.query( “gckj2gyh” )
.eq( “title” , true )
.count()
.then( (num) => {

$w( '#text9' ).text=  ''  + num; 

} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

someone, please help me.
tell me the wrong part.

This here is the name of your DATABASE —> “gckj2gyh” ?
You are searching in the “title” -Field for true or false values?

Did you also have synced your Live & Preview-DB?
Did you take a look onto CONSOLE ?
You should use some more console-logs!

import wixData from'wix-data';

$w.onReady(async function() {  
    let myQuery = await wixData.query("gckj2gyh")
    console.log("Query: ", myQuery)
    
    myQuery.eq("title", true).count()
    .then((num) => {
        console.log("Num: ", num)
        $w('#text9').text= String(num);
    })
    .catch( (error) => {
        let errorMsg = error.message;
        let code = error.code;
    });
});

Does this one work for you ?