I simply want code that will display an image according to a date range stored with the image in a dataset.
Have tried many examples - nothing works!
I simply want code that will display an image according to a date range stored with the image in a dataset.
Have tried many examples - nothing works!
What have you tried? What worked? What didn’t?
Hi Yisrael - thank you for replying!
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
let localDate = new Date ();
wixData . query ( ‘datetoimage’ )
. lt ( ‘minDate’ , localDate )
. gt ( ‘maxDate’ , localDate )
. find (). then ( results => {
console . log ( results )
$w ( ‘#image1’ ). src = results . items [ 0 ]. image ;
});
});
This came from Corvid and I cannot get it to work.
I “inherited” this website for music and as nothing much is happening in live concerts at the moment, I thought I would put famous composers pictures on the home page - based on a date range. I am David - hope you can help!
and… I am very new to Code - not new to WIX tho. Cheers from Australia
PS… I don’t even know how to achieve this. Is it an iFrame on my homepage to display the result??? Help???
@foxyoz525 No, you don’t want an iFrame (HtmlComponent), you want an Image component just as you have in your code. You need to work out the DB query to get the appropriate image to display.
@yisrael-wix Hi Yisrael! Hello from Melbourne.
his is the website, with a gallery, at the moment.
I don’t know how to work out the DB query. I simply don’t understand how to get pics to display. I am great with databases, and this dataset is VERY simple… but I am let down by not understanding code. Can you explain more?
How to I achieve this?
@foxyoz525 What do you have in your DB collection?
@yisrael-wix Very simple… minDate, maxDate and image
Yikes! I never look in there!
@foxyoz525 In order to do a query, you’ll need data in the fields, and some of your fields are empty.
@yisrael-wix I added those 2 pics this afternoon. I can easily add the dates.
@foxyoz525 OK, your query basically looks OK. You’ll need an Image component with the ID #image1. See the gt() and lt() API docs for more details.
@yisrael-wix Ok Yisrael… I have no idea what you mean, but I will go searching for an Image component? I cannot find it anyway in the menus to ADD TO PAGE… so I am again lost. But thank you for your help. Dave
Can you write an example code for me? Please?
The Random Image example shows how to display an image on the Home page. Instead of random, you need to use the result of your query.
@yisrael-wix (tears) How do I select random?