我正在使用Codeigniter 3.我想制作问题和答案测验类型表格

I am trying to make Quiz type form in which i will store all data then will insert in the end . I want to store data so when person press previous button that person will able to see last ans he has given so he can update and if person press next should be able to get data like quiz. I want you to help me with this please

Model :

  <?php

class NewSystem_m extends CI_Model{
         public function insert_entry($data)
        {
         $query =  $this->db->insert('newsystem',$data);
                   if ($query >0) {
                                 $last = $this->db->insert_id();
                                 $q = $this->db->get_where('newsystem', array('ID' => $last));
                                return $q->row();
                        }else{
                                return false;
                        }
        }   

        public function getquestions($table,$cntrltype)
        {

        $query = $this->db->query("SELECT * FROM $table WHERE ctrltype = '$cntrltype' limit 1");

                        if($query->result()>0){

                            return $query->row_array();                     
                        }else
                        {
                                return  false;
                        }
        }

//model
           public function Previous($id,$table,$ctype)
        {
                        $query = $this->db->query("SELECT * FROM $table WHERE ctrltype = '$ctype' AND ID = '$id'-1 limit 1");

                      if($query->result()>0){
                          return $query->row_array();                    
                        }else
                        {
                                return  false;
                        } 
        }

           public function Next($id,$table,$ctype)
        {

                $query = $this->db->query("SELECT * FROM $table WHERE ctrltype = '$ctype' AND ID = '$id'+1 limit 1");

                      if($query->result()>0){
                          return $query->row_array();                    
                        }else
                        {
                                return  false;
                        } 
        }

        public function insertQA($id,$table,$ctype)
        {                             /*    $checking = array
                ( 
                        'ID' => $id,
                        'ctrltype' => $ctype

                 );  

                               $query= $this->db->get_where('demo',$checking);
                                $count = $query->num_rows();
                                if ($count === 0) {*/
        $insert = array
               ( 
                        'ID' => $id,
                        'ctrltype' => $ctype,
                        'tablename' => $table,
                        'Ctrl' => $this->input->post('txtcntrlid'),
                        'description' => $this->input->post('txtdescription'),
                        'Questions' => $this->input->post('txtques'),
                        'Ans' => $this->input->post('txtans')
                 );  
                                $this->db->insert('demo',$insert);
                                       // }

            }

} 
?>

Controller:

  public function index()
    {
        $this->load->view('New System/First');
    }

    public function FamilySelection()
    {

        $this->load->view('New System/Second');
    }

        public function FamilySelectionQuestion()
    {
                $cntrltype =  $this->input->post('optradio');


                $cate = $this->session->userdata('categorization');
                $assess = $this->session->userdata('assessmenttype');

                if($cate == 'High' && $assess == 'San20')
                {
                    $table = 'sans20high';
                    $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Medium' && $assess == 'San20')
                {   
                    $table = 'sans20moderate';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);

                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Low' && $assess == 'San20')
                {   
                    $table = 'san20low';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'High' && $assess == 'One Year')
                {   
                    $table = 'highyearone';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Medium' && $assess == 'One Year')
                {   
                    $table = 'moderateyearone';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Low' && $assess == 'One Year')
                {   
                    $table = 'lowyearone';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'High' && $assess == 'Two Year')
                {   
                    $table = 'highyeartwo';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Medium' && $assess == 'Two Year')
                {   
                    $table = 'moderateyeartwo';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Low' && $assess == 'Two Year')
                {   

                $table = 'lowyeartwo';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);  
                $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'High' && $assess == 'Three Year')
                {   
                    $table = 'highreatoyearthree';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Medium' && $assess == 'Three Year')
                {   
                    $table = 'yearthree_moderate';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Low' && $assess == 'Three Year')
                {   
                    $table = 'lowreatoyearthree';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'High' && $assess == 'Full')
                {   
                    $table = 'highfull';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Medium' && $assess == 'Full')
                {   
                    $table = 'moderatefull';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }
                elseif ($cate == 'Low' && $assess == 'Full')
                {   
                    $table = 'lowfullato';
                        $data = array(
                        'table'  => $table,
                        'ctype'  => $cntrltype
                    );
                    $this->session->set_userdata($data);
                    $data['post'] =$this->NewSystem_m->getquestions($table,$cntrltype);

                    $this->load->view('New System/Third',$data);
                }

                else
                    {
                        redirect('NewSystem');
                    }

                    if($data['post'] == FALSE){redirect('NewSystem/FamilySelection');}         

    }

    public function submitnewsystem()
    {
          $this->form_validation->set_rules('txtSname', 'System Name', 'required');
          $this->form_validation->set_rules('txtdescript', 'Description', 'required');
          $this->form_validation->set_rules('optradio1', 'Categorization', 'required');
          $this->form_validation->set_rules('optradio2', 'Standard Type', 'required');
          $this->form_validation->set_rules('optradio3', 'Assessment Type', 'required');

            if ($this->form_validation->run() === FALSE)
            {
                $this->session->set_flashdata('validatesubmit',validation_errors());
                redirect('NewSystem');

            }
            else
            {
              $data = array
              (
                'Name' => $this->input->post('txtSname'),
                'Description' => $this->input->post('txtdescript'), 
                'categorization' => $this->input->post('optradio1'), 
                'standardtype' => $this->input->post('optradio2'), 
                'assessmenttype' => $this->input->post('optradio3'),
                'InsertedbyIP' => ':1', 
                'Insertedby' => 'Ahsan', 
                'insertedDateTime' => date("Y-m-d h:i:sa")
              );
               $inserted = $this->NewSystem_m->insert_entry($data);

               if($inserted)
                        {
                            $session_data = array(
                                'UserID' => $a,
                                'PWD' => $b
                                'Name' => $inserted->Name,
                    'categorization' => $inserted->categorization,
                                'assessmenttype' => $inserted->assessmenttype

                            );
                            $this->session->set_userdata($session_data);
                        }

                 redirect('NewSystem/FamilySelection');
    }

View:

 <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">


<link rel="stylesheet" href="<?php echo base_url()?>assets/bootstrap/css/bootstrap.min.css">
<style>
body {
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

/* style the container */
.container {
  position: relative;
  border-radius: 5px;
  background-color: #f2f2f2;
  padding: 20px 0 30px 0;
} 

</style>
</head>
<body>

<br><br><br>
<div class="container">
  <form method="post" action="<?php echo base_url()?>NewSystem/nextprevious">
    <h2 style="text-align:center"><u>Question from Selected Control</u></h2>
<input type="text" name="txtids" value="<?php echo $post['ID']; ?>" hidden>
      <div class="row">
                <div class="col-md-1"></div>
        <div class="col-md-2">
    <div class="form-group">
      <label>Control ID :</label>

  </div>
</div>
<div class="col-md-6">
    <div class="form-group">

    <input type="text" class="form-control" name="txtcntrlid" value="<?php echo $post['Ctrl']; ?>" readonly="readonly">

  </div>
</div>

      </div>
          <div class="row">
                <div class="col-md-1"></div>
        <div class="col-md-2">
    <div class="form-group">

   <label>Control Description :</label>

  </div>
</div>
<div class="col-md-6">
    <div class="form-group">


    <input type="text" class="form-control" name="txtdescription" value="" placeholder="Enter Control Description">

  </div>
</div>

      </div>
            <div class="row">
                <div class="col-md-1"></div>
        <div class="col-md-2">
    <div class="form-group">

  <?php $questions =explode("?",$post['Questions']);

  ?>
    <label>Control Question :</label>

  </div>
</div>
<input type="text" name="txtques" hidden value="<?php echo $post['Questions']?>">
<div class="col-md-9">
    <div class="form-group">
<?php foreach ($questions as $value) {?>    
    <input type="text" class="form-control" name="txtquestionsdis" value="<?php echo $value;?>" 
    <?php if($value==''){echo  'hidden';}?> readonly="readonly">

<?php }?>

  </div>
</div>
<!-- yeh form hai -->

      </div>
            <div class="row">
                <div class="col-md-1"></div>
        <div class="col-md-2">
    <div class="form-group">

   <label>Control Answer :</label>

  </div>
</div>
<div class="col-md-6">
    <div class="form-group">

    <input type="text" class="form-control" name="txtans" value="<?php echo $this->session->userdata('Ans'); ?>" placeholder="Enter Control Answer">

  </div>
</div>

      </div>
      <div class="row">

        <div class="col-md-12 text-center">

          <input type="file" name="txtfile">
        </div>
      </div><br>


         <div class="row">


<div class="col-md-12 text-center">

    <label class="radio-inline"  style="margin-left: 0%">
      <input type="radio" name="optradio" value="met">Met</input>
    </label>
     <label class="radio-inline" style="margin-left: 15%">
      <input type="radio"  name="optradio" value="notmet">Not Met</input>
    </label>
</div>

      </div><br>

           <div class="row">
        <div class="col-md-12 text-center">
          <button type="submit" value="0" name="btnpre" class="btn btn-primary btn-lg">Previous</button>
          <button type="submit" value="1" name="btnnext" class="btn btn-primary btn-lg">Next</button>
        </div>
      </div><br>






  </form>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

<script src="<?php echo base_url()?>assets/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

I found a solution my self by updating row on clicking next and previous button which helping me alot ! Thanks every one for helping me.