Unique ID in Database

Hello everyone,

I have a database that has the following columns: question,answer,question_id.

The way that the app works: In the beginning there is a question and answer pair, user chooses the answer, presses “Next Question” button, the answer is sent back to the backend, and new q&a pair pops up. By the time, I save every answer,question to the database, and I set the unique ID for every entry like this
Screenshot 2024-01-08 at 15.21.09

Every time a new question pops up the values in the previous q&a placeholders change, so I would like the read the q&a pairs for the previous questions from the database by using unique ID, and assign them again. However I realized something interesting with the unique ID behaviour.

This screenshot is from the workflow that creates the data entry. As you can see the question id is 2 (even though this is the first element in the db):
Screenshot 2024-01-08 at 15.48.44

However this is what I see in the database after the creation, as we can see the ID here is 1:

The problem is, I use question IDs to assign previous questions to their placeholders. Since there is this mismatch of IDs for some reason, I cannot get the right one, I can’t even view it on the screen.

I am new to bubble and a bit confused :slight_smile: Looking forward to all the help!


I wouldn’t use question_ids to traverse the questions on the screen.

You can set up a custom state (number) called current to the page (or to the text field, or repeating group, whichever you want), and then show the element #current from the list. When next or prev is clicked, you just change the current custom state.

See the demo below:

And the textbox in the center just displays the item #current: (prev_next is the name of the page).

And the next and prev is just updating this custom state (just prev is below).

I hope that helps.

Thank you for the detailed answer!

To be more specific, the number of questions and the questions itself are not deterministic. The algorithm decides which question to ask and how many questions will be asked. So in one workflow, I am both writing to the database, and reading the previously saved questions (distinguishing by the ID). So I don’t see how can I make a list out of this, since it changes dynamically.

Everything is dynamic in Bubble. You dont need to make a list. It is already there as a list. So, when your algorithm adds another question to your current user or to the database, no mattwe where it is saved, you can get the next one or previous one. The current custom state in the previous answer doesn’t even know the number of items in the list, and it doesn’t care.

Probably, we need more details of your structure to answer more.

Could you explain a bit more the idea behind current and how can it be implemented? Sorry, I am really new to bubble, and I appreciate all the help :slight_smile:

You can check how it is setup from this page: Tests for Forum 5 | Bubble Editor

I keep these test for forum apps around as long as Bubble lets me :slight_smile:

Thank you @hergin , now I got how it works. Eventhough I think this is quite useful, it does not help my case. I am not trying to traverse the database. My task is: when the “counter > 1”, I want text box that is in a group to show the element (that has an id of 1, but keep in mind the mismatch issue I mentioned above thread) in the database.

In order to do this I am using conditional where I check the counter and change the data source so that it points to the element in the database. I tried with retrieving the data like #item, however that did not work. All I get is a white blank.

I hope this was a more clear description of my current issue :slight_smile: