So I’m trying to connect a database to a text box on my webpage and try to have it autoupdate daily (the content is showing quote of the day) and I’m not sure how to do that.
An example would be this website http://www.kneadpastaproject.com but I want to make the image rotation longer
I know that javascript is necessary for this part but im not sure how to do it
Does anyone have a sample code on how to do this?
Thanks
James
I don’t know exactly what you want. but for making a daily quote. this could be done by adding the day you want to post this quote to the website. like this.

Date should be in this format (YYYY-MM-DD). I put it manually. and the title would have your quote.
in your code you should find the current date in the same format and find the quote with the same date.
let currentDate = yyyymmdd();
// function to change the date format.
function yyyymmdd() {
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length === 1) && (d = ‘0’ + d);
(m.length === 1) && (m = ‘0’ + m);
yyyymmdd = y + ‘-’ + m + ‘-’ + d;
return yyyymmdd;
}
wixData.query("Quotes")
.eq('postDate',currentDate)
.find()
.then( (results) => {
if (results.length>0){
$w(‘#text2’).text=results.items[0].title;
}
.catch( (err) => { let errorMsg = err; } );
});
});
I hope this would help.
Hi,
In addition to @ahmdjsalhi 's comment, If you want to match the date to the quote the query should look like this:
wixData.query("quotes")
.eq("date", currentDate)
.find()
.then( (results) => {
if(results.length>0){
$w('#text2').text=results.items[0].title;
}
} )
.catch( (err) => {
let errorMsg = err;
} );
Good luck ![]()
oh you’re right !
actually I made it that way! but I was trying something and copied it by mistake hahahaha.
good job Or
thanks.
ps: I edited the code. (for the dearest future reader).
Thank you guys very much for your help!!
Hey, I kept on getting unexpected token error around the .catch part. Do you know why is that?
maybe you miss something.
be sure about closing all the braces } / ) in your whole code.
Line 27 shows the red dot which they said is an unexpected token. When I took the dot off, it highlights catch instead. tried solutions that I found online but couldn’t figure out why ;-;
@james5288 yeah it’s a braces problem.
put this in line 27 }});
Hi, sorry to bother you with this once again but when I added the code, now there is an unexpected token on 27:2. The one in 32:1 became a dead token because there is 1 more of }. when I removed } . the unexpected token became the one in 28:1 (which is the original error). When I replaced } with / 28:3 became an unexpected error of unterminated regular expression.
@james5288 I wish I could reach your code, could you copy it for me to fix it?
$w.onReady( function () {
//TODO: write your page related code here…
let currentDate = 20181009();
// function to change the date format.
function yyyymmdd() {
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length === 1) && (d = ‘0’ + d);
(m.length === 1) && (m = ‘0’ + m);
yyyymmdd = y + ‘-’ + m + ‘-’ + d;
return yyyymmdd;
}
wixData.query("QuoteoftheDay")
.eq('postDate',currentDate)
.find()
.then( (results) => {
if (results.length>0){
$w(‘#text14’).text=results.items[0].title;
}
}/);
. catch ( (err) => {
let errorMsg = err; } );
});
Here it is ![]()
here it is:
also, don’t change let currentDate = yyyymmdd ();
it finds the current date by itself. keep it this way.
$w.onReady( function () {
//TODO: write your page related code here…
let currentDate = yyyymmdd (); // do not change this!
// function to change the date format.
function yyyymmdd() {
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length === 1) && (d = ‘0’ + d);
(m.length === 1) && (m = ‘0’ + m);
yyyymmdd = y + ‘-’ + m + ‘-’ + d;
return yyyymmdd;
}
wixData.query(“QuoteoftheDay”)
.eq(‘postDate’,currentDate)
.find()
.then( (results) => {
if (results.length>0){
$w(‘#text1’).text=results.items[0].title;
}
})
. catch ( (err) => {
let errorMsg = err; } );
});
Hey, thanks for the help bud!
Just one more quick problem, when I used the code, now there’s an error message saying that wixData is not defined. What kind of error would this be?
@james5288 put this at the top of everything
import wixData from ‘wix-data’;

