Skip to content
Advertisement

How do I store various nested lists with dynamic options and multiple levels?

I need to create several forms with a format similar to the following.

1. Select This
2. Select All of the following:
    1. First
    2. Second
3. Select One of the following:
    1. First
    2. Second

Some of the forms will be a simple list, some will be nested one or two additional levels. Normally, I would store each level in a database with a parent column. The part that has me stumped is the “Select One” (or select multiple) list items.

I can figure out the displaying and the recording that will need to happen, but I am having a difficult time wrapping my head around the best way to store the questions and allow for the necessary hierarchy and differing selections. I am sure there are a few ways to do it, just looking for advice.

Advertisement

Answer

Since I am finding it unlikely that I will receive a response, I kept looking for a solution. The solution I am going with for now is to add a “rule” column to the row in the database. In the example above, the database will look similar to the following:

list_level, list_text, rule
"1", "Select This", null
"2", "Select All of the Following", "all"
"2.1", "First", null
"2.2", "Second", null
"3", "Select One of the Following", "one"
"3.1", "First", null
"3.2", "Second", null

This will allow multiple dynamic levels as well as custom rules to be developed and programmed as needed.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement