title: Codeigniter - How to store the test selected answer after pagination
body: <p>I am creating a test system, this is my first codeigniter project. I am able to make the pagination, so each page will only display one question and click next button to go next question. Now my problem is when user answer one question and go next but when he/she go back to previous question the answer doesn't appear there. Below are my code:</p>
  
  <pre><code>Controller.php
  ...
  $config['per_page'] = 1; 
  $page = ($this-&gt;uri-&gt;segment(4)) ? $this-&gt;uri-&gt;segment(4) : 0;
  $data['question'] = $this-&gt;TestModel-&gt;getAllQuestion($id, $page);
  $data['links'] = $this-&gt;pagination-&gt;create_links();
  $this-&gt;load-&gt;view('TestView',$data);
  
  TestView.php
  &lt;form name="testform" action="" method="post"&gt;
      &lt;div class="bs-question"&gt;
      &lt;?php
          foreach ($question as $row)
          {
       ?&gt;
          &lt;h3&gt;&lt;?php echo $row-&gt;question; ?&gt;&lt;/h3&gt;
          &lt;br/&gt;
          &lt;br/&gt;
          &lt;div style="padding-left:20px;"&gt;
             &lt;?php
               foreach ($answer as $an)
              {
             ?&gt;
              &lt;div class="radio"&gt;
                &lt;label&gt;
                  &lt;input type="radio" name="optionsRadios" id="optionsRadios1" value="&lt;?php echo $an-&gt;aid?&gt;"&gt;&lt;?php echo $an-&gt;answer ?&gt;
                &lt;/label&gt;
              &lt;/div&gt;
              &lt;?php } ?&gt;
              &lt;/div&gt;
              &lt;?php
                 }
              ?&gt;
              &lt;br/&gt;
              &lt;br/&gt;
              &lt;?php echo $links; ?&gt;
              &lt;div class="clearfix"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How can I store the selected answer, when user go back previous/next qeustion?</p>
  
  <p>What I do:</p>
  
  <pre><code> $('#next a').click(function () {
                      var link = $(this).get(0).href; // get the link from the DOM object
                      var form = $('#testform'); // get the form you want to submit
                      var segments = link.split('/');
                      // assume the page number is the fifth parameter of the link
                      $('#page').val(segments[3]); // set a hidden field with the page number
                      form.attr('action', link); // set the action attribute of the form
                      form.submit(); // submit the form
                      return false; // avoid the default behaviour of the link
                  });
  </code></pre>
  
  <p>In my controller:</p>
  
  <pre><code>if($this-&gt;input-&gt;post('optionsRadios')){
          $s_v = array(
              'questionno'. $this-&gt;input-&gt;post('qnsid') =&gt; $id = $this-&gt;input-&gt;post('qnsid'),
              'optionsRadios'. $this-&gt;input-&gt;post('qnsid') =&gt; $id = $this-&gt;input-&gt;post('optionsRadios')
          );
          $this-&gt;session-&gt;set_userdata($s_v); //add the ID to your session
      }
  </code></pre>
  
  <p>In my view:</p>
  
  <pre><code>    &lt;input type="radio" name="optionsRadios" &lt;?php if( $this-&gt;session-&gt;userdata('optionsRadios'.$question-&gt;qid) &amp;&amp; $this-&gt;session-&gt;userdata('optionsRadios'.$question-&gt;qid) == $row['aid'] ) echo "checked";
  else echo ""; ?&gt; value="&lt;?php echo $row['aid']?&gt;"&gt;
  </code></pre>