Can't figure out selector loop

Hi, so I’m fairly new to coding and still learning A LOT. So please don’t judge me if my code looks bad.

I’m having an issue with trying to use a for loop that will run through and fill the elements on the page. What I’m trying to do is have a for loop run though and search the database for the order that I’ve put the modules in (e.g. 1-30). This should then return the name of the module. Once the module name has been found I would like it to fill in the textbox that goes with that name (e.g. textBox1, textBox2, textBox3 exc.) I’m trying to use i to fill in the associated textbox number but I can’t seem to figure it out.

I’m not sure how to get this to work or if this is even the right way to go about this. I would assume I should use a for loop so I’m not repeating this 30 times. Any help or advice would be much appreciated!

for (var i = 1; i <= 30; i++) {
    wixData.query("SiteModules")
        .eq("Order", i)
        .find()
        .then((results) => {
            let moduleName = results.items[0].moduleName;
            $w("#moduleName" + i).text = moduleName;
        })
}

It’s better not run so many queries in a row.
Instead you can do something like:

let toQuery= [];
for (let i = 1; i < 31; i++){
    toQuery.push(i);
}
wixData.query("SiteModules")
.hasSome("order", toQuery)
.ascending("order")
.find()
.then(r => {
    let items = r.items;
    for(let i = 0; i < items.length; i++){
    $w("#moduleName" + i).text = items[i].moduleName.toString();
    }
})

[Updated, since I don’t if the moduleNames are unique, so I changed to .find() just in case].

P.S I used “order” and not “Order” because as far as I know, a field key cannot start with a capital letter.

Thank you! You just solved a lot of my problems! I wasn’t aware that field names could be capital as well but for some reason it is on my site. Wix makes has the field set to read-only as well so I can’t change it. Thanks agin J.D. for your help!

@cade_wright field name can start with a capital letter, but field keys cannot. And in code we always use field keys.