I am printing question number with the correct answer as 1 and wrong answer as 0.

Now I would like to count how many correct answers for each question.

Example of this:
Question number: 8
00110

For this example there are two correct answer.

$scoree = 0;
		$intt = 0;
		$sqlll=question();
			while($infoo = mysql_fetch_array( $sqlll)) {
		
	  
			echo "<hr><br><strong>{$infoo['Que_ID']}</strong><br />\n";
			$_Session1=$infoo['Que_ID'];
  
		$man=count($_Session1);
			while($infooo = mysql_fetch_array( $man)) {
				$answer1 = $infooo['Que_Answer1'] == $infooo['Ans_Answer1'];
				$answer2 = $infooo['Que_Answer2'] == $infooo['Ans_Answer2'];
				$answer3 = $infooo['Que_Answer3'] == $infooo['Ans_Answer3'];
				$answer4 = $infooo['Que_Answer4'] == $infooo['Ans_Answer4'];
				if ( $answer1 && $answer2 && $answer3 && $answer4)
				{
				echo ("1");
				
	
				}
	
				else
				{
				echo ("0");
				
				}
	
			}
			}

Recommended Answers

All 4 Replies

Member Avatar for diafol
SELECT `QuestionId`, `Que_Answer1` + `Que_Answer2` + `Que_Answer3` + `Que_Answer4` + `Que_Answer5` AS Num_Answers FROM table ORDER BY `QuestionId`

it prints 00110. Now will I be able to just have the 1 and add them and print this.

Member Avatar for diafol

What's the datatype? Should be tinyint.

yes it is

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.