2015-11-03 88 views
0

我正在研究一个简单的测验网络应用程序,我想验证提交按钮上的每个问题,显示正确的问题并添加标记。验证正确答案并在PHP测验中添加标记

我创建了我的第一个问题页这样

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
?><!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Cric Quiz </title> 

    <link href="<?php echo base_url(); ?>assets/style.CSS" rel="stylesheet" type="text/css"/> 

    </head> 
<body> 

<div> 
    <h1>Cric Quiz</h1> 
</div> 

<div id='quesNo'> 
    <center>Question 01</center> 
</div> 

<div id='questions'> 
    <center>When did Australia win their first ever world cup?</center> 
</div> 

<div id='answers'> 
<input type="radio" name="year" value="1992">1992<br> 
<input type="radio" name="year" value="1996">1996<br> 
<input type="radio" name="year" value="2000">2000<br> 
<input type="radio" name="year" value="2012">2012 
</div> 

<center><a href="<?=base_url().'index.php/Questions/question_2';?>" class="button1">Next</a></center> 

</body> 
</html> 

我控制器

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Questions extends CI_Controller { 

public function question_1() 
    { 

     $this->load->view('quiz_one'); 

    } 

    public function question_2() 
    { 

     $this->load->view('quiz_two'); 

    } 
} 

如何验证我的控制器我的答案

PS:我使用的是笨

回答

0

你的方法是错误的。只需要一个函数并将问题ID传递给该函数即可。如果明天,你有1000个问题,你会创造许多功能?

首先在数据库中存储正确答案。

下一步你的HTML应具备的形式,提交表单用POST数据

发布问题ID形式后

添加在控制器此代码,

// run query to fetch data from database based on the question in 
if($this->input->post("year") == "value from database"){ 

} else { 

}