Store and get value from dataset

Hi community!

Can you help me with this issue?
I’m doing a simple counting system where text1 is on the first page and text2 on the second page.
The text1 is the main one where the counting will be done by pressing the buttons and the text2 just a mirror to see the quantity already counted.
My idea is to store the value of text1 in real time in dataset1 and pull that value in real time in text2.
It would be possible? could someone give me a way?

text1 screen

text2 screen

Already have seen this PIC. :grin:
Where is you code?

Dima my hero! :sweat_smile:

I have no code yet, don’t know how to use database :disappointed_relieved:

Ok, first of all you have to learn how to use this forum :grin:
CODE in a picture is not the best coise.
I can’t copy that code to work with it and to write all the code by hand…well not really want to do it (i am a very LAZY person) xD.

So please use the CODE-TAGS which you will find here in the menu-section to input CODE. Then i will be able to COPY it and work with it. :grin:

Oh, sorry!

// Para documentação completa sobre API, includindo exemplos de códigos, visite https://wix.to/94BuAAs
$w.onReady(function () {
 //TODO: write your page related code here...
});


//====================================================

var COUNTER = 0

function count_up () {
 
  COUNTER = COUNTER+1
  console.log(COUNTER)
 return COUNTER
}

function count_down () {
 
  COUNTER = COUNTER-1
  console.log(COUNTER)
 return COUNTER
}


export function button2_click(event) {
 let myNewTextLabel = count_up()
  $w('#text1').text = myNewTextLabel.toString()
}

export function button1_click(event) {
 let myNewTextLabel = count_down()
  $w('#text1').text = myNewTextLabel.toString()
}

//====================================================

export function text1_viewportEnter(event) {
 //Add your code for this event here: 
  $w("#dataset1").count().setValue; // for just that field data only
}

Ok, after 6 or 7-times of reading your problem, i think i now understand what you want to do (hopefully) xD.

So, as i can see you already have the counting process.
Now you surely wants to know how to get the counting-digit into your database.

But there are still some questions.

  • you use a dynamic-page? (dynamic-dataset)?

  • or do you use a normal one?
    and how is structured your database?

In which column the results should be recorded?

This is an example-code of how to achieve your aim…

$w.onReady( () => {
 $w("#myDataset").onReady( () => {
   $w("#myDataset").getItems(0, 1))
     .then( (result) => {
       let items = result.items;
       let totalCount = result.totalCount;
       let offset = result.offset;
     } )
     .catch( (err) => {
        let errMsg = err.message;
        let errCode = err.code;
      } );
  } );
} );

You can use simply getItems in combination with …

$w("#myDataset").setCurrentItemIndex(variable here);

…and this one would be also be an option…

let itemObj =$w("#myDataset").getCurrentItem();

Now first try to do some brainstorming and to see the light in the dark :grin:

I think, i am to tired to make clear thinking. I will take a look tommorow on it again.

Just in some short sentences what my idea was.

  1. You count UP or DOWN on your main-page —> +1/-1
  2. This result you could use to set the currentIemIndex of the dataset and then simply get the data out of the current selected index(row/line) of the database and then doing what ever you want with it.
  3. Another way could be to use…
$w("#myDataset").getItems(0, 1))

…increasing the first value with your value…

let your Value = 1 (then you increase this value for example +1)

$w("#myDataset").getItems(0, 1)) ---> should get first item
$w("#myDataset").getItems(1, 1)) ---> second item 
$w("#myDataset").getItems(2, 1)) ---> third item
$w("#myDataset").getItems(3, 1)) ---> ans so on.........
$w("#myDataset").getItems(4, 1))

This would be your first step.

Thank so much for your help!
I’ll try use this.

here is my db

I’ll try to store text1 in countNumber column and text2(in other page) changes in realtime, synchronized with db or text1, if possible…

I used normal page, dynamic page is better for this?

If i would understand exactly what you want to do, then perhaps i would also suggest to use better a dynamic page.
Show an example of how your project should work…

Ok i know already you will have —> 2-Buttons for COUNTING-UP & DOWN.
And you have 2x-Text on 2-different pages, ok!

But what now? What is your idea? What do you want to do ?

  1. Just count up & down and show it in textfield on both sites?
  2. I also think that you want to store the data in a database, ok!

BUT WHAT IS YOUR MAIN-AIM ???

Try to give a better explanation, i will think about it tomorrow.

Okay, I’ll try to explain it more clearly:
First of all, I work in a hypermarket and because of the coronavirus, it is necessary to respect a maximum limit of 180 people on site.

Initially I created an app using kodular (bit . ly / 39CaYVM) to keep a person at the entrance of the store counting and the cell phone screen mirrored on a TV for everyone to see, however, the store has two entrances and the app I made only counts one at a time, not both as a total.
I had the idea of risking it, creating a website on wix even for being online, so I only access the page where “text2” is on TV and the page where “text1” is accessed by cell phone to make a count.

Ok, try to reconstruct it.

  1. You have 2 entrances (2-counting points). I do not know how you realize it to count the customers, but this is your problem :grin: (perhaps a light-sensor), ok!

  2. You have 2-TVs —> 1 for every entrance to show the RESULTS on SCREEN, ok checkecd!

  3. Your problem; at moment you are just able to count on just 1 of the 2-entrances, ok checked.

Ok, i do not know how you get the data from your counting-system into the wix-database, but if you have the data the rest should be easy.

  1. My question would be, how do you get the counting-data to wix database?
  2. And why you need 2-different pages?
export function button1_click(event) {
$w('#myTotalCountText').text = SumMyCountings(Number($w('#input1').value), Number($w('#input2').value)).toString()}
function SumMyCountings(page1, page2) {
  return page1 + page2;
}

Ok, i think i am really to tired right now, can not find clear thoughts.
I will think about it.

And you tell me, how you want to get the DATA (the countings of the customers and get them onto your site).

See ya.

To count customers have two peoples, one in each entrance.

  1. the database value is from “text1”, realtime sync(if possible)
    Why I use database? Well, I don’t know if is possible to get value from text1 direct to text2 in other page. So, I sync texts with database.

  2. Why different pages: if I count in cellphone the tv screens don’t count together, database here is to get all sync… :sweat_smile:

Hello again, now we come closer :rofl::sweat_smile: i hope my brain works better today then yesterday night xD —> REFRESHED! :rofl:

Ok, first you said that an app counts the customers on one of the entrances, now you say it is ddone by to persons on (one on each entrance).

Now i understand! You make this little menu so that this 2-persons who counts the customers on each entrance, can click on the counting button in your COUNTER-MENU ??? Is that the plan? :joy: ok.

Why not doing an automatic COUNTER-PROCESS with a light-sensor and ARDUINO-SYSTEM, but well, this is another problem :grin:.

Back to topic:
Let me try to describe the situation how i understood you right now.

Simple-description:

  1. You have 2-PERSONS on EACH-ENTRANCE.
  2. This person counts the number of your customers. (Count-UP & DOWN).
  3. Then they input the values manually onto a website by using a phone or a PC-Desktop).
  4. For this process you wants to create a webpage, where this two counting persons, can COUNT your customers with the help of a CLIK-COUNTER.
  5. The sum of both counting-results is shown later on 2 different TV-Screens.

So if this is your process then i got it.

And yes then you should better use a database, optional you could also use the local-Wix-Storage. But this choice is on you. If you want later play with the gathered data for some stats and evaluation diagram, so take the database. If you just wants to show the actual number of the customers inside your shop, so you could also use just the Wix-Storage…
https://www.wix.com/corvid/reference/wix-storage#top

Ok, how would i do this if i would be YOU? :sweat_smile:

In this case you would have:
1x SCREEN-PAGE → this will show your COUNTER on both TV-screens, which are connected to the wix SCREEN-PAGE-SITE.

1x COUNTER-PAGE → on this page the counting process will be done by the two counting-persons of your shop (clicking on your created COUNTER-MENU).

  1. Creating a CLICK-COUNTER —> already done by you.
  2. Creating a page to show the counter on —> TV-Screens (1-page on both TVs).
    So you will need just 1-page which will shown on both screens → SCREEN-PAGE.
  3. Both of your personal opens the same Clickcounter on the —> COUNTERPAGE and starts counting. Every click INCREASES OR DECREASES the COUNTER.

The value of the counter (shown in a TEXT or INPUTFIELD or what ever), will be saved in the Wix-Storage. (This was the process on your COUNTER-PAGE. Your actual value is saved.)

Now we are going to your SCREEN-PAGE.
On this page you create a refresh-function —> which will refresh the site all 5-10 seconds for example and load the counting results out of the storage/or DATABASE (as you want) and show them in TEXT / INPUTBOX or whatever on screen!

Yepp thats it! Isn’t it?

:sweat_smile::sweat_smile::sweat_smile::sweat_smile::sweat_smile:

Yeah, that’s right!
I took a look here and this Local Wix-Storage seems perfect, I didn’t know about it, I will try to use it.

Do it :grin: you will make it, i am sure.

And a last suggestion.

Why not doing all on JUST ONE PAGE ?

You would have the COUNTER and THE OUTPUT on the same page, but on TV-SCREEN you would just showing the OUTPUT-PART of the page.

Just an idea. Do not know if it fits to your project :grin:

Honestly, I didn’t think about it :sweat_smile:
thank you!

Yepp! Because —> Then everything could be much easier xD, without any Wix-Storage and databases. Just pure showcase on the screen.

Really don’t know how to store in wix-storage too :neutral_face:

I want to store “text1”, because even if I make a single page if it updates or the user leaves the value is reset, this cannot happen.

import {local} from 'wix-storage';

$w.onReady(function () {
 //TODO: write your page related code here...
  local.setItem('text1', $w('#text1').text);

 const text1 = local.getitem('text1');
  $w('#text1').text = text1;
});

This is the SAVING-PART on SITE-A.

local.setItem("key","value");
local.setItem('key', $w('#text1').text);

And this is the RETRIEVING-PART on SITE-B

let value = local.getItem("key")

First you save your DATA with a —> key
Then you load this DATA from the storage on site-B, using the key.

I’ll be back in few hours xD, see ya!:grin:

When I refresh page, the num return to 0, don’t store :sob:

Wow!! Finally I get this code to solve my issue:

Counter page:

// Para documentação completa sobre API, includindo exemplos de códigos, visite https://wix.to/94BuAAs

import {local} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {
 //TODO: write your page related code here...
 var text1 = local.getItem("text1");
   local.setItem( "text1", $w('#text1'));
   $w('#text1').text = text1;
});

//====================================================

var COUNTER = 0

function count_up () {
 
  COUNTER = COUNTER+1
  console.log(COUNTER)
 return COUNTER
}

function count_down () {
 
  COUNTER = COUNTER-1
  console.log(COUNTER)
 return COUNTER
}


export function button2_click(event) {
 let myNewTextLabel = count_up()
  $w('#text1').text = myNewTextLabel.toString()
  local.setItem('text1', $w('#text1').text);
}

export function button1_click(event) {
 let myNewTextLabel = count_down()
  $w('#text1').text = myNewTextLabel.toString()
  local.setItem('text1', $w('#text1').text);
}
//====================================================

View page:

// Para documentação completa sobre API, includindo exemplos de códigos, visite https://wix.to/94BuAAs

import {local} from 'wix-storage';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady(function () {
 //TODO: write your page related code here...
    $w('#text2').text = local.getItem("text1"); // "value"
    setTimeout(() => wixLocation.to(wixLocation.url), 3000) //time in milliseconds
});

I want to thank everyone for their help and tips, especially @russian-dima for all the effort !!