No solution for daily random items every day

Hello Adalo community,

I have read every single post in this forum related to display daily items (also posts related to random picker component) but I cannot find a suitable or clear solution.

I’m creating a social app in which everyday the user has to answer to a Question of the Day, that is, answer a different question every day, picked from a database of questions, and post it so other users can see.

To make it simple, there are three collections: Users, Posts and Questions.

In the Questions collection there is a database of 17 questions (just a small example to test as there will be more questions) assigned to an QuestionID property in sequential order. There is also one relationship with Users (Many Questions, one User) and one relationship with Posts (One Question, many Question Posts). There is also a QuestionDate property (only date not hours). The Users collection has, among other essentials such as username etc, a RandomQuestionID property and a CurrentDate Property (only date not hours).

When the user clicks in the button of Question of the Day, I have managed to display a random question using the RAND(1,17) function, but I CANNOT make it to appear only one question per day. Currently, when you click in the button, you get a different question every time.

Also the Home Screen has an action to Update → Logged In User → CurrentDate Property → Start of Today. But I have problems with the logic related Start of Today and Current Time.

ISSUE → What I need is to show only one question every day so that a new question pops up every day for users to answer it.

There is something that I’m missing I need some help and clarification here. I’m just a beginner and I cannot find an easy solution. I’ll mention some experts I’m learning a lot from in this forum: @Victor @Rozza @Yongki @theadaloguy @Ali-Bazzi @njimmy10

Thanks a lot guys!

Hello,

The work around is complex,

You could create a 4th collection let’s called “Displayed Questions”, that has the question as relationship and date, in your RAND(1,17) you could add a filter to the questions, in list visibility that the question doesn’t appear if it’s mentioned in the “Displayed Questions” collection and the date is equal to today.

The process you want is complex, that’s how I would’ve started, other experts might help too

Thanks for your quick answer. Let’s see if other experts are able to provide some help as well. I’m a bit lost on how to approach it. I thought it was not that complex. Luckily there can be an easier way or a similar solution that solves it.

I posted earlier a similar screenshot. I basically took that logic and extended it a little
Filter out any questions answered by the user


When they answer the question the answer is being logged in the questions_answered collection, with relationship to user and question, and a text string for their answer.
image

It is also updating the Question Users_Answered field with LIU.
Finally it updates the LIU record: Date field Last_Question_Answered

Then use some visibility / conditional logic to show, hide and do what you need.
Extend it by storing the last answered ID for quick retrieval.

Plenty other ways to approach it. Obviously not meant to perform with 10k questions.

Good luck :+1:

:point_right: :coffee: = :grinning:

:point_right: :sos: + :exploding_head: = :phone:

Hi @kimbo,

Your requirements are a bit vague and there are more details needed. In particular:

  • does the question has to be the same for every user or it could be different?
  • does the question has to be fully random?
  • can the question repeat next day (if it’s randomly selected then there is a possibility of repeating it for obvious reasons)
  • if repeat isn’t allowed, what should happen when all questions are displayed?

The solution will heavily depend on the details above.

However: if we accept the following conditions:

  • same question per day for all users
  • question is changed every day
  • we don’t really care about full random, it should seem random to users but not to us
  • questions repeats “in cycle” (e.g. after q17 the next day q1 is displayed)

Then a there is a quite simple solution for this, without any extra databases / links / etc.
I’ve made a video about it: https://youtu.be/-W-x4wTnkJ4

Here is the full explanation.

Step1. Prepare questions database. Put all questions there AND create numeric QuestionNumber property for each question. QuestionNumber should be sequential, from 0 to N, where N is the number of last question.
Why not to use built-in ID: it is works as autoincrement and if you remove a question from a middle you will not have a number sequence.

Step 2. You will need a number of current day. It’s relatively easy to get - add CurrentDayNumber property to Users collection, and update it with INT(current time). This should work ok, you can optimize things later by calculating current day number directly in the formula.

Step 3. As now we have a current day number which is the same for all users and a list of questions with sequential numbers the only thing left is to select one question, choosing its number based on day number.
As we know the number of questions (using count or hardcoding it), the problem above can be easily solved by using modulo function (remainder from the division). It doesn’t exist in Adalo but we can simulate it:

QuestionOfTheDay = CurrentDayNumber - ( INT ( CurrentDayNumber / NumberOfQuestions ) * NumberOfQuestions )

As an example, lets’ calculate the question for today (11th of December 2023). Let’s assume we have 17 questions in the collection.

  • CurrentDayNumber = 19702
  • INT ( CurrentDayNumber / NumberOfQuestions ) = INT (19702 / 17) = INT (1158,94118 ) = 1158
  • multiplying it by NumberOf Questions = 1158 * 17 = 19686
  • QuestionOfTheDay = 19702 - 19686 = 16

You can easily calculate the QuestionOfTheDay for tomorrow which will be 0 (that’s why you need to start from 0).

So now the only thing left is to create a single-item list of Questions, filtered by QuestionNumber = QuestionOfTheDay.

Best,
Victor.

P.S. It seems it is becoming a tradition to post buymeacoffee links here, so here is mine: https://www.buymeacoffee.com/victorandco :stuck_out_tongue_winking_eye:

WIthout coffee the wheels fall off :crazy_face:

Hello @Victor,

Thanks a lot for your effort in providing a such elaborated answer and a video. My requirements were a bit vague because I was open to different solutions that could apply to the general idea of daily random questions.

Even though I have an issue (that I will describe below), this is exactly the “simple” logic I was looking for.

However.

I have applied all the steps you carefully explained and it looks good (I guess I’ll have to wait until tomorrow at 00:00am to see if the question changes to a different one). But, I am finding the following problem:

I have two screens, Home screen and Daily Question screen.

In the Home Screen I want to display all the posts from the daily questions of users (this includes question of the day and the answer from user).

I am following the same steps you explained, to display the list of questions in the Home screen: single-item list of Questions, filtered by QuestionNumber = QuestionOfTheDay (in the video Input > QID). In this case, I am doing the only option I have: QuestionNumber = Other Components > All Screens > Question of the Day > QID

The problem is that I am not getting the same question as in the Daily Question screen (where I have included all your steps). What I get is the last question added to the database (q17).

What I expect to happen in the two screens is the following:

  • Home screen: see all the posts that users create every day, with the specific question and answer for each day.

  • Daily Question screen: Every day a new question appears and the user is able to answer and post it, so it will go to the Home screen so the other users will see it (this screen is already OK following your procedure but when user posts, the question of the day is not the same in Home screen).

Any guidance here?

P.S. Good idea to implement this buymeacoffee tradition. I will contribute to caffeine seekers! :crazy_face:
Thanks also to @Rozza for his explanation and approach!

Hey @kimbo,

My explanation was covering only the logic for displaying a daily question - I’ve left all other logic to you :slight_smile:

Either the formula in the input isn’t yet calculated when you visit Home screen or the input value is “lost”. Possible workarounds are:

  • add same input to Home screen: the formula is the same so the result will be the same
  • put calculation result to some property in Users collection and access it via Logged-In User → QID. The issue here is that you will need to be sure that you aren’t updating this property every time (only when needed) so that you don’t spend extra actions.
    Input solution seems better to me.

Best,
Victor.

Hello @Victor

I have added the formula to the Home screen as well and now it is the same.

However, I’m afraid that when a new question appears, it changes all the questions in Home screen from previous days to the current day question.

Let’s put this easy example:

  • User posted yesterday (11th December 2023) the question of the day and this is what other users see in Home screen:

Name: user
Daily Question: Question 1
Answer: Answer 1
Date posted: 11/12/2023

However, today (12th December 2023) Question 2 is displaying, and therefore, yesterday’s question post from user is also changed in Home screen to today’s question looking like this:

Name: user
Daily Question: Question 2
Answer: Answer 1
Date posted: 11/12/2023

Is there a way to prevent this from happening? That is, to change only the displayed question in Daily Question screen everyday but maintain questions from previous days answered in the Home screen.

Thanks :pray: ! I’m finding it difficult to apply all this logic.

@kimbo changing the total number of questions will definitely change the current day question ID. This is how the formula works by design.

I would advise to prepare all questions in advance.

Also you can always display user’s answers from answers collection. When a user posts an answer, you create a record there (you can search on the forum how to limit this to one record / question).
This record is linked to question (one question can have many answers) and to a user (one user can have many answers) and belongs uniquely to user and question.
Then if you would like to display a list of answers for a particular question, you simply (a) get this question somehow (e.g. single item list or a screen with current question) and (b) display the list of answers filtered by this question.

In this case, when you add another question to the collection, users still can see the list of answers for each question NOT based on its ID but based on the DB relationships.

Best,
Victor.

Forgive me if I am missing something.

If you want to display a truly random question to each user on any given day then the approach I gave does this and it doesn’t really matter about time zones, they will not get the same question again.

If you want to display the same question to all users on any given day, then it need not be random (though users can think it is) and you just have one question for each day, and store that in your collection.

Hey @Rozza

Thanks a lot for your approach and video!

I have been trying your last procedure (see quote below) and probably it can be the simplest way to do it, as I don’t need questions to appear randomly every day but to look random:

To do this, I have created a date property (date without time) in Questions Collection and assigned a date for each question from today onwards. For example: Question 1 → 12/12/2023 - Question 2 → 13/12/2023 and so on.

Then, in Daily Question screen I have the list filtered like this: All Questions > QuestionDate > is equal to > Current Time

Until this point it looks good, and I see the question assigned for today.

However, when users create the post, I have the same issue in the Home screen:

  • All the posts show today’s question (with a list filtered the same way as in Daily Question screen), so tomorrow, when the new question appears, the questions from yesterday’s posts in Home screen will also change to the current question of the day.

A bit tricky but I tried to explain as better as possible :grimacing:

Do you know how to act here or maybe filter correctly in Home screen?

1 Like

Post or DM a cloneable link :+1:

To put a final update to this issue, I managed to solve it by applying @Rozza 's logic :ok_hand: (many thanks!)

In Questions Collection:

  1. Assigning a date to each question in the database
  2. Add QuestionDate Property.
  3. Many to Many relationship with Users Collection and One question Many Posts relationship with Posts Collection.

Now ready to display a daily question:

  1. A list of All Questions with two custom filters: Current Question > Users answer (M2M relationship) > does not contain > Logged In User and QuestionDate > is equal to > Start of Today

Thanks a lot also to @Victor for spending some time on this issue as well and giving his approach.

1 Like

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