不定選項 完成考試系統的處理辦法

來源:互聯網
上載者:User

痛點一
取得題目數組,大亂後輸出,調整不同的輸出順序

 步驟
 1
       取得題目數組 $subject
 2
 取得輸出的數組
  var arrayLen = count($subject);
 $tempKey = range(0,arrayLen);
        $tempKey = array_rand($tempKey);
        for($i=0;$i<count($tempKey);$i++)
        {
  $smartyArr[$i]["subject"] = $subject[$tempKey[$i]];
  $smartyArr[$i]["subjectType"] = 題目類型
 }
        return $smartyArr;
3
 介面輸出
 根據題目類型,取得對應的模版,然後輸出
        建立一個題目id的預設數組 ,建立一個題目類型的預設數組
 
 <input type="hidden" name="課件id" value="{% $課件id %}">
        題目一
              <input type="hidden" name="subjectID[]" value="{% $題目id %}">
        <input type="hidden" name="subjectType[]" value="{% $題目類型 %}">
              選項一 <input type="radio" name="p_{% $題目id %}" value="">
       選項二 <input type="radio" name="p_{% $題目id %}" value="">
  題目二
              <input type="hidden" name="subjectID[]" value="{% $題目id %}">
        <input type="hidden" name="subjectType[]" value="{% $題目類型 %}">
              選項一 <input type="radio" name="p_{% $題目id %}" value="">
       選項二 <input type="radio" name="p_{% $題目id %}" value="">
4
 提交後的php頁面處理
 $prjectID = $_POST['課件id'];
        $subjectIDArr = $_POST["$題目id"];
        $subjectTypeArr = $_POST["$題目類型"];
 //取得答案
 $subjectKeyArr ;
        //使用者答案數組
 $keyArr =array();
 //答案正確數
 $trueKey = 0;
 for($i=0;$i<count($subjectID);$i++)
        {
   
  $subjectID = $subjectIDArr[$i];
  $subjectType = $subjectTypeArr[$i];
                if($subjectType=="多選")
  {
   $tempKey = implode(',',$_POST["p_{$subjectID}"]);
  }else{
   $tempKey = $_POST["p_{$subjectID}"];
  }
  //取得一道題的答案
  $subjectKey = $subjectKeyArr["{$subjectID}"];
  $keyArr[] = $tempKey;
  //如果答案跟預先設定的一樣
  if($subjectKey == $tempKey)
  {
      $trueKey = $trueKey+1;
  }
  
 }
 var $showMsg = "您沒有通過考試";
 if($trueKey>="預先設定的答案數")
 {
  var $showMsg = "您順利通過考試";
 } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.