Randomly display a record (quote) on a new screen

Hi
I’ve been trying to set this up myself but nothing seems to work.
How do I display the next database record every time a button is clicked?
For example.

A button is clicked on home page, the user is taken to another screen and he sees a quote.
Every time the user clicks on the button on the home screen he’s shown a new quote. (could be picked randomly from the database collection record)

I created a database collection and added the quotes there.

What would you guys recommend?
Thanks in advance.

1 Like

Hi @hellonewuser,

Welcome to the forum!
There are few options for this, in particular:

  1. you can use “Random Picker” component from the Marketplace (it’s free). You will need to setup this component to connect it to “Quotes” collection, select “Trigger Click Action” (what happens on click) and then add an action to link to another screen. On that screen you will have “Current Quote” available and you can display it.
    Random picker should select a random record from the Quotes collection every time.

  2. Another approach will be to use randomly generated numbers. For this you will have to:

  • upload the quotes to Quotes collection and make sure you don’t delete any
  • as a result you will have list of quotes with incremental IDs (say, from 1 to 10)
  • add a property to Users collection, call it a “QuoteID”
  • on the Home screen, add a button to go to the next screen
  • on this button, add an action to update Logged-in User → QuoteID, make it a function RAND (1,10) - use lowest and highest number from IDs in Quotes collection
  • the next action will be to go to another screen
  • on this another screen, add a list. Make it a list of Quotes, filtered by ID = Logged in User → QuoteID.
    As a result, this list will display only one quote (the one with ID which is equal to the randomly generated QuoteID).
  1. You can use Random number, Adalo API calls with limit and offset, but this is a bit too complicated.

Just in case, there were similar questions before - you can search through the forum.

Best regards, Victor.

1 Like

THANKS!
could you please specify here

  • add a property to Users collection, call it a “QuoteID”

should it be a text or number?

and I tried the random picker btw, but it doesn’t do the job. the quote is always inside the frame and the text is never displayed correctly.

thanks again

Hi @hellonewuser ,

Adding to the explanation of @Victor ,

I have made an example app here,

It is cloneable, so you can see what is inside,

Here is a screenshot related to your asking,

1 Like

Hello @hellonewuser,

You’re welcome.

Random picker works perfectly, you just didn’t set it up correctly. There is a setting called “Display Text”, by default Random Picker puts the 1st property of the collection inside it. You can replace this setting with anything you want.

In regards to ID - it needs to be numeric. @Yongki has shared the example already :slight_smile:

Best,
Victor.

thanks a lot!

Thanks! it worked!

1 Like