使用HTML表单中的分数修改不同页面上的MySQL表

问题描述:

关于此问题

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.

此建议是通过向用户提出几个不同的问题来实现的.根据他们给出的答案,将为MySQL表中的产品列表分配分数.表格末尾,得分最高的产品ID将是赢家,因此将是最适合用户的产品.

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.

在此说明中,我将仅使用2个问题.第一个问题称为阶段1".第二个问题称为阶段2".

In this explanation, I will just use 2 questions. The first question is called 'Phase1'. The second question is called 'Phase2'.

阶段1:带有单选框输入的HTML Web表单使用户可以在多个值之间进行选择.根据通过单选框输入的值,将现有表中的特定列插入到新创建的临时表中名为"Phase1"的列中.该临时表名为"Advice".阶段1列包含不同产品的要点列表.

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.

因此,这是表单第1阶段中发生的情况的分步说明:

So this is a step-by-step explanation of what's happening in Phase 1 of the form:

  1. HTML单选框输入使用户可以在4个值之间进行选择.
  2. 使用以下列创建一个临时表(名称:"Advice"):"ProductID","ProductName","Phase1","Phase2"
  3. ProductID和ProductName列由有关产品的数据填充.该数据是从称为"Computers_F1"的现有表中获取的.

那么,在用户回答问题"Phase1"之后会发生什么?

So what happens after the user answers question ''Phase1"?

  1. 根据用户输入的单选框值,阶段1"列由"1","2","3"或"4"列更新,其数据来自名为"Computers_Phase1"的现有表.
  2. 临时表现在包含三个填充的列. "ProductID","ProductName"和"Phase1".

希望到目前为止,一切都有意义.包含第二个问题的阶段2应该基本上执行与阶段1相同的操作. 请注意,第2阶段将在下一个HTML页面上进行,并提供新表格,然后将其输出到phase2.php.但是,这意味着需要将临时表"Advice"从phase1.php传递到phase2.php. 所以到目前为止,这实际上是我的问题.因为显然,PHP不允许将MySQL SELECT查询存储到$ _SESSION变量中.我已经考虑过将"Advice"表的内容保存在一个php数组中.但是,这样做的缺点是,我无法再使用MySQL查询来在阶段2中修改表.

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.

我需要能够在page2.php脚本中修改表"Advice".这是必要的,因为我想在几个不同的问题之后进一步添加列.在所有问题的最后,我想创建一个名为总计"的列.此列中的值将是阶段1",阶段2"等中值的总和.因此,最后在总计"中得分最高的行将是最适合用户的产品.

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.

简短的答案是:在会话中不存储数据,而仅存储用户的选择.
在最后一页上完成所有计算.

Short answer would be: store in the session not the data but only user's choice.
On a final page do all your calculations.

正确的答案:临时表应该是最后的希望.仅在无法使用常规RDBMS机制的情况下才必须使用.

Proper answer: temporary table should be action of the last hope. Have to be used only if no regular RDBMS mechanisms can be used.

您的逻辑很可能可以映射到标准联接.但是,由于逻辑仍然未知,所以无法提供更多信息.

Most likely your logic can be mapped to standard joins. But it's impossible to tell more as logic is still unknown.