I have a regular page on which I’d like to grab the appropriate user’s name to use in the title. I added my database and chose the field from the database that I want to grab, but it always grabs that field from the first item in the database. I’m doing this on a dynamic database with no problem. Is there a way that I can grab the user’s name from the appropriate (their) row in the database to populate my title, or do I have to make it a dynamic page in order to do that?
OK. I think I figured out what to do. I was already querying the database to check whether the user had rights to the page; so I added in an else after that check. This is part of the code:
wixData.query("testDB")
.eq('_id', userId)
.find()
.then( (results) => {
if ((results.items.length === 0) || (results.items[0].upUrl !== url)) {
wixLocation.to('/');
}
else {
$w('#text33').text = results.items[0].userName;
}
I tried to do it with a dataset on that page, but I was having trouble with that, and this did the trick…