facarroll Posted June 14, 2011 Share Posted June 14, 2011 I have the following code which will display a quiz result as an image representing pass or fail on a student's report page. The student may have attempted several different quizzes and sometimes repeated a quiz several times. As a result, the code displays every attempt and every result. Is there some way that I can have the code display as follows; 1. Display only the most recent successful quiz for each quizTitle, (in other words display a pass image for a successful quiz, but no duplicate pass images if the same quiz has been passed more than once.) 2. If a quiz has been failed, there is a fail image displayed. If a student makes several unsuccessful attempts, a fail image is displayed for each fail. I would like the code to cease displaying a fail image as soon as a quiz has been returned to and successfully passed. In other words, instead of a student accumulating several fail images, just one successful attempt will cause all previous fail images to stop being displayed. I hope someone can make sense of this and suggest a solution. <?php $query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' ORDER BY quizTitle ASC"); while ($row = mysql_fetch_array($query1)){ echo "{$row['quizTitle']} <br />\n"; echo "{$row['userDate']} <br />\n"; if ("{$row['passState']}" == 1) {echo "<img src='pass.png' /><br />\n";} if ("{$row['passState']}" == 0) {echo "<img src='fail.png' /><br />\n";} } ?> Link to comment https://forums.phpfreaks.com/topic/239325-conditional-select-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.