Random Image from Local DB wont display

Hello all.

I’ve been struggling to work out how to pull an image from my local database on the project. I’ve already got the DB set up and working - I have another page using the Data viewer List to pull the thumbnails from the local DB images.

I’ve tried multiple ways of blocks and logic and can’t get it to display a random image from the database. My Local DB has 4 Columns: Title, Image reference for the asset, subtitle, and description (to match the Data Viewer List objects for later). I have attached screencaps of 2 ways I’ve tried and a 3rd screencap of Rollin because I used those blocks for reference.

I’m too deep in the weeds here and am running out of idea’s as I am new to this. If you have any idea’s how to pull a random .jpg extension from the Local DB and then display the image on the page I would be really grateful.

Goal: On home page, have a random greeting card display from a list of 50+ cards. I don’t want a button to randomize it; just whenever the page starts. I would create a list manually, but naming 50+ .jpg’s in the list would be bloated. Trying to keep the code clean.



Thank you in advance for any help you can provide. It’s late and I’m burnt out.

P.S. Does anyone know if I have to subscribe with a paid membership for the ability to enable multiline text in Text Input blocks? And Columns?

Get rid of this block:

2 Likes

But it also looks like you’re setting your row id variable to an image file name. Try an integer first to see if that works. If not, I can tell you how to get a proper row id from your table.

1 Like

Thank you for the suggestion. This is what I came up with - and it worked one time! Now it wont display again… Puzzling.

I tried a couple other blocks but it started getting needlessly complicated so I reverted back to the above screencap. I added an invisible data viewer so that I could try to pull “row id” blocks but then I drew a blank about where to put it so I just deleted the blocks bet kept the Viewer invisible just in case.

Ideas?
(as always, thank you for your help!)

Now you’ve taken out too much… :joy: Let me see if I can make you demo.

Here are three ways to display a random image when the screen opens:

And the project link if you’d like to try it out:

https://x.thunkable.com/copy/b8467ce31a2bed6d3be385d33a640268

2 Likes

Oh my gosh! :rofl: I should have just stopped while I was ahead and gone to sleep! This is so simple… I was totally overcomplicating it. The first one works perfectly because all of the cards are going to have the same name and only the number changes to identify it.

I added the join blocks into my own project and it works 100% of the time. You’re a godsend. Thank you! When I get better at Thunkable and start to understand more I will remember you and pass it forward.

3 Likes

You’re welcome! I’m glad it’s working now. I’ve learned a great deal from other folks here so I’m always happy to help when I can.

1 Like

By the way, unless you have another reason to use the local database, you can do this without adding any data to it. If your image files have sequential names and you know the total number of images, you can just replace the number of rows in Cards in Table 1 block in the first method I shared with an integer block (e.g. 6 if you have six images).

2 Likes

Oh I see; thank you! Thinking further then, if the final version has 50 cards but only want to pull the first 10 I could just set the integers to 1 to 10? That adds a lot of control if I’m understanding that. I’m going to test it for learning’s sake (I only have 3 cards in the prototype right now, so it’ll be 1-2, excluding the 3rd card).

Or… thinking still: I could hand pick cards and use the Random Item from List: and choose however many I want and hand pick them, using the text block with the name of the .jpg. If I’m understanding that correctly that’s really cool! Thanks @tatiang !

2 Likes

I think you’ve got it! :smiley: