I have two tables 'quiz' and 'topics'.
The relevant columns in 'quiz' are 'passState' (which returns 1 or 0 representing true/false) and 'managerId' which is a record number referring to a particular administrator.
The relevant columns in 'topics' are 'managerId' and six other columns named 'equip1' .... 'equip6' respectively, which refer to the allocation of particular quizzes to particular student groups. Each quiz can be allocated to none or any or all of the groups 'egroup1' to 'egroup6' by the allocation of true/false value to each.
The code below displays all of the required data on the page, but not in the layout I want. Despite the use of SELECT DISTINCT the data is returned in duplicate. As well as that, the image file 'tick2.png' (row 28) is not returned in any meaningful way. Firstly, it should only be returned when 'passState' has a value of 1. Secondly, it is being returned to all of the rows in the array, but only to one of the duplicate rows but randomly it seems.
I don't understand what's wrong. I appreciate that this is a long winded explanation, but I'd really appreciate some help.
<?php
//$query1 = mysql_query("SELECT DISTINCT comment, url_big, url_small, title, pdf, comment FROM topics WHERE managerId = $managerId AND $egroup = 1 ORDER BY title");
$query1 = mysql_query("SELECT DISTINCT comment, url_big, url_small, title, pdf, passState
FROM topics
INNER JOIN quiz
ON topics.managerId = quiz.managerId
WHERE ( topics.$egroup = 1
AND quiz.userId = '$userId' )
ORDER BY topics.title
");
?>
<table width="850" style="font-size:16px">
<tr>
<?php
while ($row1 = mysql_fetch_array($query1))
{
?>
<td width="45"></td>
<td width="132" style="vertical-align:middle;"><?php echo "<a href='../../wood/wood_tool_images/{$row1['url_big']}' target='_blank'><img src = '../../wood/wood_tool_images/{$row1['url_small']}' /><br />\n"; ?></td>
<td width="25"></td>
<td width="172" style="vertical-align:middle;"><?php echo "{$row1['title']} <br />\n"; ?></td>
<td width="25"></td>
<td width="132" style="vertical-align:middle;"><?php echo "<a href='../equipment/{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; ?></td>
<td width="25"></td>
<td width="112" style="vertical-align:middle; text-align:right;"><?php echo "<a href='../../wood/wood_tool_images/pdf/{$row1['pdf']}' target='_blank'><img src='../../wood/wood_tool_images/pdf/icon.jpg' /><br />\n"; ?></td>
<td width="15"></td>
<td width="132" style="vertical-align:middle; text-align:left;" ><?php echo "{$row1['comment']} <br />\n"; ?></td>
<td width="45"><?php if ("{$row1['passState']}" == 1) {echo "<img src=' ../../wood/wood_tool_images/tick2.png' /><br />\n";}?></td>
</tr>
<?php
}
?>
</table>