Hi All,
I want to do 24 questions DISC personality test but I do not know how to filter value in multiple database fields and sum all value example D: ? I:? S:? C:?. I'd like to assign a value to D I S C . After that I don't what I need to use statement or query. However I'm feeling a bit lost, I'm sure the answer is simple but sometimes the documentation can feel a bit vague on a case by case basis, so please help me coding on dynamic page.
Ok, what you have to do is remove the columns no1q ... and add 3 numeric ones, let's say you want to call them responseD, responseI, responseS, responseC.
now let's pretend that the user answers S to the first question, the code will be this:
wixData.query('DISC') .eq('name', varWithTheName) //better to use the id .limit(1) .find() .then((returns) => { let item = returns.items[0]; item.responseS = item.responseS + 1; wixData.update('DISC', item)
this is used to update the data already existing in the collection, so when the user answers row is created you must assign a default value of 0 to all answers.
So maybe you can make an 'enter name' field and a start test button that creates the row when pressed.
Also I recommend that you put this code in the backend of the site so as not to overload the client
or you create numeric variables that are updated at each answer and the data is saved at the last answer
Hi, but I did not get the correct value for my total score. How to filter and count the all same value in the database but different fields
import wixData from 'wix-data'; $w.onReady(function () { wixData.query("DISC") .eq("no1Q","D") .eq("no2Q","D") .eq("no3Q","D") .eq("no4Q","D") .eq("no5Q","D") .eq("no6Q","D") .eq("no7Q","D") .eq("no8Q","D") .eq("no9Q","D") .eq("no10Q","D") .eq("no11Q","D") .eq("no12Q","D") .eq("no13Q","D") .eq("no14Q","D") .eq("no15Q","D") .eq("no16Q","D") .eq("no17Q","D") .eq("no18Q","D") .eq("no19Q","D") .eq("no20Q","D") .eq("no21Q","D") .eq("no22Q","D") .eq("no23Q","D") .eq("no24Q","D") .count() .then((results)=>{ $w('#sumD').text = results.toString() }) });
maybe use multiple .eq () functions to find exactly the database line with the result
wixData.query('DatabaseName') .eq('databaseField',comparisonValue) .eq('databaseField',comparisonValue) .eq('databaseField',comparisonValue) .find() .then((results)=>{ //here you can add what comes back from the database })