title: I am making an online exam system in codeigniter
body: <p>I am developing an exam system in codeigniter. My database has table called questions which has 7 cols question, option1,2,3,4, correct answer and tag. I want to fetch and match results.</p>
  
  <p>My view coding is</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="&lt;?php echo base_url() ?&gt;main/economics_validation" name ="f" method="post" accept-charset="utf-8"&gt;
                &lt;?php
                
                foreach($eco as $economics) 
                      {
                  ?&gt;
         &lt;li&gt;
              &lt;h3&gt;&lt;p&gt;Q&lt;?php echo $economics-&gt;id ?&gt;  &lt;?php echo $economics-&gt;question; ?&gt;&lt;/p&gt;&lt;/h3&gt;
              &lt;p&gt;&lt;?php echo $economics-&gt;option1 ?&gt;
              &lt;input type="radio" name="&lt;?php echo $economics-&gt;id ?&gt;" value="&lt;?php echo $economics-&gt;option1 ?&gt;"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;?php echo $economics-&gt;option2 ?&gt;
              &lt;input type="radio" name="&lt;?php echo $economics-&gt;id ?&gt;" value="&lt;?php echo $economics-&gt;option2 ?&gt;"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;?php echo $economics-&gt;option3 ?&gt;
              &lt;input type="radio" name="&lt;?php echo $economics-&gt;id ?&gt;" value="&lt;?php echo $economics-&gt;option3 ?&gt;"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;?php echo $economics-&gt;option4 ?&gt;
              &lt;input type="radio" name="&lt;?php echo $economics-&gt;id ?&gt;" value="&lt;?php echo $economics-&gt;option4 ?&gt;"&gt;&lt;/p&gt;
         &lt;/li&gt;
          &lt;?php 
                    }
          ?&gt;
              
          
      &lt;/ul&gt;
      &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my controller coding is </p>
  
  <pre><code>public function economics_validation()
      {
          $result['d']=$this-&gt;model_db-&gt;calculate_marks();
          $this-&gt;load-&gt;view('marks',$result);
      }
  </code></pre>
  
  <p>and my model coding is </p>
  
  <pre><code>public function calculate_marks()
      {
          $query = $this-&gt;db-&gt;query("SELECT * FROM questions");
          $a = $query-&gt;result();
          $q2 = $this-&gt;db-&gt;get('questions');
          $marks = 0;
  
              foreach($a as $corr)
              {
                  for($i = 1; $i &lt;= $q2-&gt;num_rows();$i++)
                  {
                      if($corr-&gt;correct_answer == $this-&gt;input-&gt;post($i))
                      {
                          $marks = $marks + 1;
                      }
                      else
                      {
  
                      }
                  }
  
              }
  
  
          return $marks;
      }
  </code></pre>
  
  <p>I'm unable to get the correct result. The problem is that it is telling incorrect answer as correct. </p>