Hey there,
I want to build a recommended list of products based on a questionnaire that a visitor completes. For example, if my questionnaire is for cars, I will ask them if they like small cars, medium sized cars, or large sized cars. If they select medium sized cars, I will provide a picture and product details for a 4-Runner, Chevy Equinox, etc.
How do I use a database, link it to a questionnaire that a visitor fills out on my website, then provide specific results from my database?
Thanks for the help, and let me know how I can explain more clearly.
Joel
Hi Joel,
I will take your simple example, to explain the idea.
What you need is a collection of all the items that can be suggested. So, lets model one for cars. We need a table with car details, picture and the criteria:
- model
- make
- picture
- size (small, medium, large)
So, if user chooses small, you can go and query the collection by the field size and show the suggestions.
You can display the results using the repeater bound to a dataset. You set the filter (size in this case) on a dataset to narrow down the results.
You can read more about repeaters:
On setting Dataset filters dynamically:
I hope this helps. Let me know if you need further assitance.
Thanks Giedrius. I was able to easily make the repeater; however, I will have to learn a bit more of the coding to get the filters to work correctly. I’ll take some time to learn this myself.
I think there is still one component in this example that I am missing though. In your answer above, it sounds like I will filter on “small”, then my repeater will show results for all cars that fit the label “small” as well as any other information I want to include from the datatable.
The component that is missing relates to the filter. Instead of having a visitor select “small” from the filter, I want to create a form or questionnaire for them, which automatically displays the filtered results.
Example of the steps:
- Visitor goes to my website and sees a form or questionnaire
- Visitor answers “small” for the question “What size car do you want?”
- Visitor clicks submit, then is sent to a list of results (repeater linked to a database)
Again, thanks for helping out. Let me know if I can clarify in any way.
Joel
One idea, that jumps to my mind is to pass the selection in one page to the other via query parameters.
Say you have car size and fuel type inputs. In the first page on submit you could execute:
const size = $w('#size').value
const fuel = $w('#fuel').value
wixLocation.to(`/suggestions?size=${size}&fuel=${fuel}`)
In suggestions page you can receive those parameters and use them in the dataset filter for the repeater:
$w('#dataset1').setFilter(
wixData.filter()
.eq('size', wixLocation.query.size)
.eq('fuel', wixLocation.query.fuel)
);
Don’t forget to import wixLocation module
import wixLocation from 'wix-location'
You can read more about it here: