duancaoqin6683 2019-03-21 14:30 采纳率: 0%
浏览 23

我正在寻找如何在完成测验CodeIgniter PHP后存储结果

I will try and make this as detailed as possible because ive been marked down before. There is a select quiz file outside of the codeigniter framework, it then takes you to 1 of 5 quizzes. Below is the computing quiz (each are the same apart from the questions and answers). The files below are stored in the view folder. The Play Quiz file is used to show all of the questions and answers. It gets the questions and answers from a database called multi_login and from a table called quiz. When the user has selected the answers and clicked submit, it will run the next block of code ive put down below. It uses arrays to check whether the answer is right or wrong, if it is right then it sets the background colour to green and adds 1 to score. The total of score is then displayed at the bottom of the quiz to show the users score. I have already used the model folders file at the bottom of the page, to select the table i want "quiz". I want to be able to store the score's number after the user has completed the quiz to be stored in a table called report into a column called score. Please help, i am using phpmyadmin for my database etc. I hope this is detailed enough, if not just comment.

Play Quiz code (for explanation):

<h1>Play the Computing Quiz!</h1>

<form method="post" action="<?php echo base_url();?>index.php/Questions/resultdisplay">


<?php foreach($questions as $row) { ?>

<?php $ans_array = array($row->choice1, $row->choice2, $row->choice3, $row->answer);
shuffle($ans_array); ?>

<p><?=$row->question?></p>

<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[0]?>" required> <?=$ans_array[0]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[1]?>"> <?=$ans_array[1]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[2]?>"> <?=$ans_array[2]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[3]?>"> <?=$ans_array[3]?><br>


<?php } ?>

<br><br>
<input type="submit" value="Submit!">

</form>

After the submit button is clicked, it will sent the user to this page:

<h1>Play the Computing Quiz!</h1>

<?php $score =0; ?>

  <?php $array1= array(); ?>
  <?php $array2= array(); ?>    
  <?php $array3= array(); ?>
  <?php $array4= array(); ?>
  <?php $array5= array(); ?>
  <?php $array6= array(); ?>
  <?php $array7= array(); ?>
  <?php $array8= array(); ?>

     <?php foreach($checks as $checkans) { ?>
           <?php array_push($array1, $checkans); } ?>


    <?php foreach($results as $res) { ?>
           <?php array_push($array2, $res->answer); 
                 array_push($array3, $res->quizID); 
                 array_push($array4, $res->question); 
                 array_push($array5, $res->choice1); 
                 array_push($array6, $res->choice2); 
                 array_push($array7, $res->choice3); 
                 array_push($array8, $res->answer); 
           } ?>


       <?php 
           for ($x=0; $x <10; $x++) { ?>

<form method="post" action="<?php echo base_url();?>index.php/welcome/index">  


<p><?=$array4[$x]?></p>


  <?php if ($array2[$x]!=$array1[$x]) { ?>

       <p><span style="background-color: #FF9C9E"><?=$array1[$x]?></span></p>
       <p><span style="background-color: #ADFFB4"><?=$array2[$x]?></span></p>

  <?php } else { ?>

       <p><span style="background-color: #ADFFB4"><?=$array1[$x]?></span></p>

       <?php $score = $score + 1; ?>

<?php } } ?>

<br><br>

<p><b>Your Score: </b></p>
  <p><b><?=$score?>/10</b></p>

<input type="submit" value="Play Again!">

</form>

Model file:

class quizmodel extends CI_Model {

    public function getQuestions()
    {
        $this->db->select("quizID, question, choice1, choice2, choice3, answer, subject");
        $this->db->from("quiz");
        $this->db->where("subject",'computing');


        $query = $this->db->get();

        return $query->result();

        $num_data_returned = $query->num_rows;

        if ($num_data_returned < 1) {
          echo "There is no data in the database";
          exit();   
        }
    }
}

Selecting Quiz

After selecting computing quiz

quiz image 1

quiz image 2

after clicking submit

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度