Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:07:17+00:00 2026-06-15T01:07:17+00:00

I am trying to work my head round this, I am using the following

  • 0

I am trying to work my head round this, I am using the following code to check the answers to a quiz and output either CORRECT or INCORRECT depending on the result of the comparison, and if the answer field is black (which only comes from the feedback form) a different message is displayed.
I cant quite work out how to apply the php count function in this situation though, what im trying to get it to do it count the amount of CORRECT and INCORRECT answers and add the two together, and then I can work out a % score from that.

        <?php
// Make a MySQL Connection
// Construct our join query
$query = "SELECT * FROM itsnb_chronoforms_data_answerquiz a, itsnb_chronoforms_data_createquestions
q WHERE a.quizID='$quizID' AND a.userID='$userID' and q.quizID=a.quizID and
a.questionID = q.questionID ORDER BY a.cf_id ASC" or die("MySQL ERROR: ".mysql_error());
$result = mysql_query($query) or die(mysql_error());

// Print out the contents of each row into a table 
while($row = mysql_fetch_array($result)){
if ($row['correctanswer'] == ''){echo '<tr><td style="color:blue;">Thankyou for your feedback</td></tr>';}
elseif ($row['correctanswer'] == $row['quizselectanswer']){
echo '<tr><td style="font-weight:bold; color:green;">CORRECT</td></tr>';}
else {echo '<tr><td style="font-weight:bold; color:red;">INCORRECT</td></tr>';
}}
?>

Iv found this example and have been trying to work out how to work it in, but cant think how to count the results of an if statement with it ?.

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
$result = count($people);

echo $result;
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:07:19+00:00Added an answer on June 15, 2026 at 1:07 am

    Simply increase some counter in each branch of your if/elseif/else construct…

    $counters = array( 'blank'=>0, 'correct'=>0, 'incorrect'=>0 );
    // Print out the contents of each row into a table 
    while($row = mysql_fetch_array($result)){
        if ( ''==$row['correctanswer'] ) {
            echo '<tr><td style="color:blue;">Thankyou for your feedback</td></tr>';
            $counters['blank'] += 1;
        }
        elseif ( $row['correctanswer']==$row['quizselectanswer'] ) {
            echo '<tr><td style="font-weight:bold; color:green;">CORRECT</td></tr>';
            $counters['correct'] += 1;
        }
        else {
            echo '<tr><td style="font-weight:bold; color:red;">INCORRECT</td></tr>';
            $counters['incorrect'] += 1;
        }
    }
    
    echo '#correct answers: ', $counters['correct'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get my head around javascript inheritance and this code doesnt work
Im trying to work with following code i getting this error at xsltProcessor.importStylesheet Error
I've been trying to work my head around this but my .htaccess powers just
I've been banging my head against a wall trying make this work for a
I've been racking my head trying to get Nhibernate to work with a byte
i am trying to work out the following problem in Java (although it could
I'm trying to work with French characters. For whatever reason, PHP won't output them
I am trying to work out the correct behavior to string multiple callbacks together.
So I'm trying to work on a Canvas demo, and I want this square
I have the following models and I'm trying to work out how to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.