function getQuestionAndAnswerPairByUid($uid) { $result = getUser_SecurityByUid($uid); $returnResult = array(); $randList = array(0, 1, 2); while ($row = mysql_fetch_array($result)) { $answer = $row['answer']; //echo $answer; $temp = getSecurityBySid($row['sid']); $question = mysql_fetch_array($temp)['question']; $localResult = array(); $localResult['question'] = $question; $localResult['answer'] = $answer; $i = rand(0, count($randList) - 1); // echo $i; // echo $randList[$i]; $returnResult[$randList[$i]] = $localResult; array_splice($randList, $i, 1); //array_push($returnResult,$localResult); } return $returnResult; }
/** * Created by ChenguangBai * Date: 2016/2/18 * Time: 23:32 */ include_once "DBHelper.php"; include_once "getUser_Security.php"; include_once "getSecurity.php"; session_start(); $uid = $_SESSION['uid']; $user_security = getUser_SecurityByUid($uid); $data = array(); while ($row = mysql_fetch_array($user_security)) { $answer = $row['answer']; $sid = $row['sid']; $security = getSecurityBySid($sid); $securityRow = mysql_fetch_array($security); $question = $securityRow['question']; $temp = array(); $temp['sid'] = $sid; $temp['question'] = $question; $temp['answer'] = $answer; array_push($data, $temp); } $sql = "select * from security where sid!='" . $data[0]['sid'] . "' \n\tand sid!='" . $data[1]['sid'] . "' and sid!='" . $data[2]['sid'] . "'"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $temp = array(); $temp['sid'] = $row['sid']; $temp['question'] = $row['question']; $temp['answer'] = "";