我建议您获取所有问题,而不是在您的代码中解决曾经已经显示的问题,如果您不想将它们从结果列表中取出并放入新列表中,那么您就可以将它们扔掉。
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("aldrig") or die(mysql_error());
$result = mysql_query("SELECT * FROM spg WHERE approved='1'") or die(mysql_error());
$answers = mysql_fetch_array($result);
start_session();
if (isset($_COOKIE["answers"]))
$alreadyShownAnswers = json_decode($_COOKIE["answers"]);
else
$alreadyShownAnswers = array();
$answerToShow = $answers[$randomIndex];
$alreadyShownAnswers[] = $answers[$randomIndex];
unset($answers[$randomIndex]);
$answers = array_values($answers);
echo "<div class='contentTitle'><h1>";
echo $answerToShow;
echo "</h1></div>";
$_COOKIE["answers"] = json_encode(alreadyShownAnswers);
?>
像这样的东西?
编辑:
使用 cookie 或 session 的方法
start_session();
$_COOKIE["answer1"] = $answer1;
$_SESSION["answer2"] = $answer2;
现在,当您想在重新调整后再次检索这些值时,请执行此操作。
start_session();
$answer1 = $_COOKIE["answer1"];
$answer2 = $_SESSION["answer2"];
使用 JavaScript 进行持久存储使用草坪椅:http: //brian.io/lawnchair/
例子:
var store = new lawnchair({name:'testing'}, function(store) {
// create an object
var me = {key:'brian'};
// save it
store.save(me);
// access it later... yes even after a page refresh!
store.get('brian', function(me) {
console.log(me);
});
});
编辑2:
用新代码更新了第一个代码块,我没有对此进行测试,但类似的东西应该可以工作。