In regard to this question How to put MySQL table into session variable and using the table on next page?, I would like to explain what I'm trying to do here.
I have a website that contains a form, through which users can answer questions. At the end of the form, the goal is to advice users about which product is best for them.
This advice is achieved by asking users several different questions. Depending on what answers they give, a list of products in a MySQL table will be assigned points. At the end of the form, the Product ID with the most points will be the winner and thus will be the product that is best for the user.
In this explanation, I will just use 2 questions. The first question is called 'Phase1'. The second question is called 'Phase2'.
Phase 1: a HTML web form with a radio box input gives users the choice between multiple values. Depending on the value that has been inputted through the radio boxes, a certain column from an existing table is inserted in a column named 'Phase1' in a newly created temporary table. This temporary table is named 'Advice'. The column Phase1 contains a list of points for the different products.
So this is a step-by-step explanation of what's happening in Phase 1 of the form:
- HTML Radio box input gives users the choice between 4 values.
- A temporary table (named: 'Advice') is created with the following columns: 'ProductID', 'ProductName', 'Phase1', 'Phase2'
- Columns ProductID and ProductName are filled by data about the products. This data is fetched from an existing table called 'Computers_F1'.
So what happens after the user answers question ''Phase1"?
- Depending on which radio box value is inputted by the user, column Phase1 is updated by column '1' '2' '3' or '4', whose data comes from an existing table named 'Computers_Phase1'.
- The temporary table now contains three filled columns. 'ProductID', 'ProductName' and 'Phase1'.
Hopefully it all makes sense up until now. Phase2, which contains the second question, should essentially do the same thing as Phase1. Note that phase 2 will take place on a next HTML page, with a new form being served and then outputted to phase2.php. This, however, means that the temporary table 'Advice' needs to be passed from phase1.php on to phase2.php. So this is actually my problem up until now. Because apparently, PHP doesn't allow MySQL SELECT queries to be stored into a $_SESSION variable. I have considered saving the content of the 'Advice' table in a php array. However, the downside of this would be that I cannot use MySQL queries anymore to modify the table in phase2.
I need to be able to modify the table 'Advice' in the page2.php script. This is necessary because I want to further add columns after several different questions. At the end of all the questions, I want to create a column named 'Total'. The values in this column will be the sum of the values in 'Phase1', 'Phase2' and so on. So in the end the row with the highest score in 'Total' will be the product that is best for the user.
Hopefully you guys can help me with this one. Maybe there is something wrong with the design of the system. Suggestions on how to improve the system would be highly appreciated.