php - Count of same records from two columns using if condition -


i have table question_attempts. table having 2 columns rightanswers , youranswer.

i want count of records rightanswer=youranswer. entire code actually.

$quizsections = mysql_query("select * quiz_sections"); while($quizsectionsrslt = mysql_fetch_array($quizsections)){ $quizsectionsid        = $quizsectionsrslt['id']; $quizsectionsheading   = $quizsectionsrslt['heading']; $quizsectionsquizid    = $quizsectionsrslt['quizid']; $quizsectionsfirstslot = $quizsectionsrslt['firstslot']; echo $quizsectionsheading."<br />"; $quizslots = mysql_query("select * quiz_slots `quizid`=$quizsectionsquizid limit ".($quizsectionsfirstslot-1).", 10"); while($quizslotsrslt = mysql_fetch_array($quizslots)){     $quizslotids = $quizslotsrslt['questionid'];     $questions = mysql_query("select * question_attempts `questionid`=$quizslotids");     $num_rows = mysql_num_rows($quizslots);     while($answercount = mysql_fetch_array($questions)){         $answercountrslt = $answercount['questionid'];         echo $rightanswer = $answercount['rightanswer'];         echo $youranser = $answercount['responsesummary']."<br />"; //here want display count of rightanswer , count of wrong answer.     }     }     echo "total questions : ".$num_rows."<br /><br />"; } 

use below:

$rightanswercount=0; $badanswercount=0;      $questions = mysql_query("select * question_attempts");         while($answercount = mysql_fetch_array($questions)){     $rightanswer = $answercount['rightanswer'];     $youranser = $answercount['youranswer'];     if($youranser == $rightanswer)             {                 $rightanswercount=$rightanswercount+1;             }             else             {                $badanswercount=$badanswercount+1;             }         }  echo "right count=".$rightanswercount; echo "bad count=".$badanswercount; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -