How can I use Airtable to present an image in my app where the image corresponds to a random row?

Hi. I am using an Airtable table to pull out random items from a couple of columns/fields. In the Airtable, I have four fields - OptionA, OptionA_Image, OptionB, OptionB_Image.

I want my Thunkable app to show the image that corresponds to the random item that is pulled out of the table. The app is getting a random item from OptionA and OptionB fields successfully and I have created the variables “RandomOptionA” and “RandomOptionB”. I can’t work out how to get the app to show the image that is in the cell for the matching rows for the random items that are pulled. Can anyone help?

How are you getting random items from Airtable? Presumably, you’re getting a random row number, assigning that to a variable, and then using that variable to retrieve the image you need.

Hi @tatiang , thanks for responding. I have an Airtable structure with the images in it like this:

I am using the following block structure that pulls two random items from OptionA and OptionB and presents them as the text in two buttons. I want to show images also with the buttons but obviously want to show the image that corresponds to the random image chosen. This is how I’ve done the blocks to get the random items:

I have two image components in the design, and have played around with the “Set Image_OptionA’s picture to…” but I don’t know how to reference the row chosen at random by the command that gets the random OptionA and OptionB text. Do I need to set another app variable?

Any help would be really appreciated.

Yes, you do need a variable for that. The random item block is only useful if you do not need to know which row was chosen. In your case, you do need to keep track of that.

Set a variable to random from 1 to [number of rows in data source]. And then get the list item # using that variable as the #.

Thanks again for your help @tatiang . I previously had the code choosing a random integer from rows 1 to X but changed it because the rows will often be added to and I didn’t want to keep changing the row numbers in the block.

I was trying to find a way of the app always choosing at random from all the rows that are within the data source with entries. Is there any other way to do it maybe?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.