Single dataset with 6 fields.

Hi.

WIX has guided me to Corvid for this, I thought WIX would be able to do it but as I try and comprehend the information here in the corvid forum I can see I was probably being naive.

I don’t want this just to be done but I’m not even sure how complex my problem really is.

I come from a completely non-coding background, any ideas would be extremely grateful as initial direction would save me a huge amount of wasted time.

I have a dataset named 6 words.

The dataset has a blank title field followed by 6 columns one - two - three - four - five - six.

These columns (one - six) are populated with rows of random words - dream - flipper etc.

I am hoping to have WIX / Corvid pick 6 RANDOM word from the dataset (spreadsheet) and display the in 6 ‘text boxes’ on a member page.

I want this to happen every time they navigate away from the page and come back.

Ie. 6 random words displayed from the dataset - they go to another page - 6 random words displayed from the dataset - they go to another page…and back…and so on.

I have linked a ‘6words dataset’ to each of the 6 text fields on the member page.

Everything seems ‘set up’ ubt there is no randomization of words from the dataset being displayed. I think this might be where Corvid comes in. Some kind of code that will access the dataset and display the random words. I guess that is why I am here.

Despite the fact of coding if needed, I have no idea of the actual scale of the problem I am facing. Is this undoable to a seasoned Corvider? Is it undoable for someone like me? Can I reach this goal with study of the Corvid forum?

If someone can point me in the right direction? Is there a page that I will view and say - “That’s it!?”

I am reading as much as I can but am swimming in information right now.

I know you will all have your own stuff to do, even a point towards the right answer would save me a huge number of wasted hours.

I hope I am ok posting this here, I don’t want to have found the wrong place.

I have attached a pic of the member page. I’ve kept the site completely basic with an eye on trying to understand how things actually work.

Thanks for your time in advance, all the best, ste.

How does it work? each member has a row with different 6 words?

thanks for getting back, appreciate it.

the ‘6words’ dataset is imported from an excel file I set up myself.

I haven’t filled in the Title field (although I guess I could) and it looks like:

Title One Two Three Four Five Six
Hey got green keal load flip
joy hear now lol just jail
best clip as I fill made
dear…
.
.
.

The members do not have anything to do with this.
They haven’t entered this previously.
They have no knowledge of it and will not ‘affect’ it in any way at any time.

They only time they even know about this imported excel file is when they navigate to a single “normal / regular” member page called ‘Six Words’. (The page could be named anything - it was the attached image).

Thinking of just one user at a time:

If ‘Geoff’ navigates to his member page ‘Six words’ he will find:

I have put 6 text boxes (if that is the way for this to be shown and be done).

Ignoring the fact that I have tried to connect each box to the dataset ‘6words dataset’ which I now believe is completely wrong way to do things (I think).

I aim to (somehow) have either 6 fields from a ‘random row’ or 6 random placed cells from the '6words dataset = imported excel spreadsheet) put on the screen.

The user will not affect them in any way, they will be read only (hopefully), they will just see them there on the screen. That’s it.

If it is possible that when they navigate away from the page and come back there will be another random set of 6 words from the imported ecxel file = ‘6words dataset’ that would be amazing.

They just keep seeing a different random set of six words drawn from the ‘6words dataset’ every time they come back.

No input, no nothing, just a different set of words every time Geoff comes back to the ‘6words’ member page.

If it is possible I would like that to happen for everyone who goes to their own ‘6words’ member page.

They don’t affect the imported exceel file → ‘6words dataset’ that is shown on the attached page.

Bob would just see a set of random 6 words drawn from the imported excel file.
So would Sally, so would Paul and so on.

I’m not sure if that needs code to pull a random set of words from the ‘6words dataset’ when each person goes to there on personal member page ‘Six Words’ but that is what I am working towards.

6 random words pulled out and displayed.

Thanks for getting back, I hope I haven’t gone on too much but I just wanted to hopefully give you an idea of what I am trying to do.

thanks again, all the best, ste.

Well, it’s possible with code. And there’s more than one way to do it.
I’ll write here something that’s easier to explain and requires less code (but it requires adding another field to the database). Personally I’d do it differently but it’s easier if you’ve never used code.
So, I’m assuming that the number of rows is known in advance (otherwise we’ll need to add a step to the process).

So it goes like that:
On the editor, click the data-set and set the number of items to display to 1.
Connect the fields to the dataset.
In you database add a column recordNumber (field type: number) and add number to each row: 0, 1, 2, 3…40 (let’s say 0 is the first row and 40 is the last number)
Write this code:

import wixData from 'wix-data';
$w.onReady(function () {
$w("#dataset1").onReady( () => {//use your dataset property name
let random = Math.floor(Math.random() * 40);
  $w("#dataset1").setFilter( wixData.filter()
  .eq("recordNumber", random)
);
});
})

P.S. in this case it’ll pull a random row. If you want to create different combinations taken from several rows, it’s also possible but a little bit more complicated.

Hi J . D.

A random line would be great.

I really appreciate your help.

I used your code without changing the name of the dataset as I only have the ‘6words dataset’
which has the little label above it called #dataset1.

I assigned number of items to display as 1.

I added the recordNumber field into the dataset ( I put it at the end of the row as I couldn’t fit it between ‘Title’ and ‘one’ field,

When I ran it in preview it keeps on bringing back the first row of 6 words.

When I run it in publish mode i just get the placeholder texts - one (field in 6words)

I have attached the picture of the code on screen.

It is working for 6 words in the first row so it is accessing it now.

I wonder can you see where I am going wrong.

Could be difficult from such a distance?

Thanks if you can, you have helped me a lot, cheers, ste


.

i can see you have some code lines (the default onReady function) before my code. Delete it and try again.

  • the code you pasted fits to 41 lines (0-40) if you have different number of lines you should change the number 40 in my code to your maximum row recordNumber.

And I’l also put here an alternative approach.
In this approach you delete the dataset from the page and work directly with your database.
I this approach you don’t need the recordNumber column, you don’t need to know the number of rows in advance, and you all random combinations are possible, not only random rows

import wixData from 'wix-data';
$w.onReady( function() {
    wixData.query("MyCollectionName")//use he name of your collection (It's case sensitive)
    .find()
    .then((res) => {
        let items = res.items;
        function generateRandom(){
            return Math.floor(Math.random() * (items.length  - 1));
        }
        $w("#text1").text = items[generateRandom()].field1;/*replace "text1" by the property name of your         textbox an "field1" by the field key of your column (attention: the field key, not the field name). Do the same in the following lines */
        $w("#text2").text = items[generateRandom()].field2;
        $w("#text3").text = items[generateRandom()].field3;
        w("#text4").text = items[generateRandom()].field4;
        $w("#text5").text = items[generateRandom()].field5;
        $w("#text6").text = items[generateRandom()].field6;
    })
})

J. D.

It works.

I can’t say thank you enough mate.

There’s no chance in the world I would figured that out, I just wouldn’t have been able to do it. You went out of your way for on reason at all and I’ll owe you for that. If ever we meet by chance or fate I’ll buy you a proper night out in Manchester.

I got it working in Preview and then after a bit more reading realised that you need to sync it to the Live site as they are not the same thing.

Waiting for the Live site to load was like that moment in Raiders of the Lost Ark where Indi is weighing out sand before he grabs the golden idol. Literally punched the air when it worked.

(I’m not Fonzi cool by any means).

Seeing as there’s been no huge boulder chasing me about the house so far I guess I am in the clear.

This is a conceptual art thing, the first thing I’ve ever made that will be worth listening to.

If I go all the way and I’m not deludedly blind, it is is a monster.

I couldn’t have done it without you.

When it’s live I’m coming back to let you know.

Nothing but respect for you mate, I hope you have a great week.

All the best, ste.

1 Like

https://www.youtube.com/watch?reload=9&v=aADExWV1bsM