Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
从我个人的角度来看,如果我被要求设计类似的东西,我会执行以下操作:
in_array()
每个答案(数组是正确的结果)并增加一个变量以了解有多少问题被正确回答(如果每个问题都具有相同的“值”,则有效)享受吧!
From my personal point of view, if I'd be asked to design something similar, I would do the following:
in_array()
on each answer (the array being the correct results) and increment a variable to know how many questions are answered right (that works if every question has the same "value")Enjoy!
您显然需要一个快速的缓存层。为此,我建议使用 memcached 或 APC。会话数据也可能起作用。
也就是说,您可能最好使用全栈 PHP 框架。好的缓存会为你管理。我建议研究 symfony 或 CakePHP。
然而,真正的问题是:在确定确实存在问题之前,您是否试图预先解决这个问题?这是一个糟糕的做法。在尝试解决问题之前,请确保您确实遇到了问题。
You clearly want a fast cache layer. I suggest either memcached or APC for that purpose. Session data may also work.
That said, you'd probably be better off using a full-stack PHP framework for this. A good one will manage caches for you. I suggest looking into symfony or CakePHP.
Here's the real question, though: are you trying to address this problem up-front before you have established that there actually is a problem? This is a bad approach. Make sure you have a problem before you try to solve it.
如果你必须一一显示它们,你需要将结果存储在某个地方,并且由于 http 是无状态的,你有 2 个选择:db 或 cookie。现在,我认为最好将答案存储在像这样的 var 中的 cookie 中
,然后在最后分解它们并检查结果。
If you have to show them one by one, you need to store the results somewhere and since http is stateless you have 2 choices: db or cookie. Now, in my opinion is better to store the answers in a cookie in a var like this
and then explode them at the end and check the result.
你不应该想要这样。 Web 应用程序将中间结果存储在数据库中是完全正常的。大多数应用程序每页执行多次数据库查询。
您可以使用会话。这允许您存储与用户耦合的数据。但是,会话数据也存储在某个地方,因此效率并不是将其存储在会话而不是数据库中的原因。
You should not want that. It is perfectly normal for a webapp to store intermediate results in a database. Most apps do several database queries per page.
You could use sessions. This allows you to store data which is coupled to a user. However, session data is also stored somewhere, so efficiency is not a reason to store it in a session instead of a database.
您想要做的是一种向导式流程,每个页面上都有一个“下一步”按钮。对于此类事情,将结果存储在会话中是很常见的。
如果您存储在会话中随机提取的问题,如下所示:
然后您可以迭代问题,跟踪已回答的问题。
What you want to do is a sort of wizard-style flow, with a Next button on each page. This is common to store the results in session for such things.
If you store the questions extracted randomly in session, like this :
Then you could iterate over the questions, keeping trace of the answered questions.