Setting element text from database query

I’m trying to work out how to set the text of an element on a page according to some results from a database query. However, what I’ve done doesn’t seem to do anything.

This is the code as appears in the code for the page:

import wixData from ‘wix-data’;

$w.onReady(function () {
wixData.query(“Settings”)
.eq(“Setting”, “Week 1 starts”)
.find()
.then((results)=> {
let item = results.items[0];
$w(“#text3”).text = item.toString();
});
});

I don’t think the code inside then() is executing. How do I get it to?

Hey there,

Welcome to WixCode. Looks like you’re jumping right in.

Your query looks OK, but I suspect that that your Field Key Setting is incorrect. Most likely it is not capitalized, like this: setting . You can check what the Field Key is by doing the following:

Click on the three dots menu button:

In the menu that pops up, select Manage properties:

Finally, your will see the properties of the collection column, including the Field Name , and the Field Key . The Field Key is what you want to use in your queries:\


Note: The Field Key cannot be modified.

Try this out and see what happens.

Good luck,

Yisrael

Hi Yisrael,

Yes, that was it!

Thank you very much for the swift help.

Ben

Hi,

I’d just like to re-light this thread as its the most applicable one i’ve found to my problem.

I need a button on my page to change its caption depending on a result in the database. However instead of looking for a specific value, i just need to check if there is anything present within the database.

I have a filter set on the database filtering for Logged In User, i then need to change my caption and change the hyperlink depending if there is anything in the databse that they created.

Any help would be greatly appriciated.

Tim