Jump to content

Recommended Posts

I have the following code that queries the database for the results of a quiz.

The display reports on completed quizzes, showing, line by line, the quiz title, the date of the quiz, an image of a green tick if the quiz result was correct or an image of a red cross for an incorrect result and a fractional result shoratio of correct answers.

A student can repeat a quiz numerous times, and therefore his results for a particulat quiz can display several rows with green ticks and red crosses for the same test done at different times with differing results.

I want to recode this so that the red crosses for incorrect results will no longer display once a student achieves a green tick result.

 

I've had several goes at this but my results are less than encouraging.

Can anyone help?

Do I tackle this through an altered query, or should I include conditions in the display of the array?

<?php
$query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' ORDER BY quizTitle, userDate ASC"); 

while ($row = mysql_fetch_array($query1))
{ 
         echo "{$row['quizTitle']} <br />\n";
         echo "{$row['userDate']} <br />\n"; 
         if ("{$row['passState']}" == 1) {echo "<img src=' ../../wood/wood_tool_images/tick2.png' /><br />\n";}
         if ("{$row['passState']}" == 0) {echo "<img src=' ../../wood/wood_tool_images/cross2.png' /><br />\n";} 
         echo "{$row['userScore']}".'/'."{$row['totalScore']}
?>

try

<?php
$query1 = mysql_query("SELECT DISTINCT quizTitle, userId, SUM(passState) as pass, MAX(userScore) as u_sore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' GROUP BY quizTitle ORDER BY quizTitle, userDate ASC"); 

while ($row = mysql_fetch_array($query1))
{ 
         echo "{$row['quizTitle']} <br />\n";
         echo "{$row['userDate']} <br />\n"; 
         if ($row['pass'] > 1) {echo "<img src=' ../../wood/wood_tool_images/tick2.png' /><br />\n";}
         if ($row['pass'] == 0) {echo "<img src=' ../../wood/wood_tool_images/cross2.png' /><br />\n";} 
         echo $row['u_score'].'/'.$row['totalScore'];
        }
?> 

Thanks for your advice Guru, and my apologies for not responding sooner. It looks as though I did not include enough information.

The field PassState is Boolean, and is simply 1 for a pass and 0 for a fail. The purpose of the other fields is obvious with the userScore and totalScore fields being used to publish the score as a fraction.

The page displays from left to right with the quiz title, date of quiz, a green check if success or a red cross if fail and a fraction, and this row repeats for each quiz result pass or fail.

At the moment the code displays a green image for every quiz resulting in a 1, and a red image for a result of 0 (both Boolean).

In a nutshell, I want the next correct image (result 1 and green image) to negate and remove from display (but keep in the database), all of the previous incorrect (value 0) and red images from the display.

The reason for this is that the quizzes can be quite difficult for young children, and several failed attempts with red crosses displayed for each one can be discouraging, but if a correct result (green and 1) were to remove all of the prior red images from the page display, the children would feel encouraged.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.