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?
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.
Welcome to the forum!
There are few options for this, in particular:
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.
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).
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.
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