facarroll 0 Junior Poster in Training

I'm not sure if this should go in the mysql forum of here, but probably applies to both.

I've posted some php to show what's happening with my array and code to create the database below.

I can make the JOIN query work, but it does not produce the data required by the last echo of the array unless I enter the column name passState in the first part of the SELECT query (where I don't think it is supposed to go).

The two problems that happen here are that the rows in the array are displayed in duplicate (despite using SELECT DISTINCT), and the image (filename2.png) always appears once in every pair of duplicated rows of the array instead of those rows where passState = 1, and when it does display, it seems to display in either the first or second duplicated row at random.
I hope my question is understandable. Ask me for further info if you need.
Thanks.

<?php
$query1 = mysql_query("SELECT DISTINCT comment, 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
					  ");

	while ($row1 = mysql_fetch_array($query1))
	{
echo "<img src = '../{$row1['url_small']}' /><br />\n"; 
echo "{$row1['title']} <br />\n"; 
echo "<a href='../{$row1['title']} .php'>blah, blah</a><br />\n"; 
echo "<a href='../{$row1['pdf']}' ><img src='filename1.jpg' /><br />\n"; 
echo "{$row1['comment']} <br />\n";
	if ("{$row1['passState']}" == 1) {echo "<img src='filename2.png' /><br />\n";} else {echo " ";} 
	}
?>
CREATE TABLE IF NOT EXISTS `topics` (
  `id` int(50) NOT NULL AUTO_INCREMENT,
  `managerId` int(11) NOT NULL,
  `equipname` varchar(100) NOT NULL,
  `pdf` varchar(50) NOT NULL,
  `comment` varchar(100) NOT NULL,
  `title` varchar(100) NOT NULL,
  `url_big` varchar(100) NOT NULL,
  `url_small` varchar(100) NOT NULL,
  `egroup1` int(4) NOT NULL DEFAULT '0',
  `egroup2` int(4) NOT NULL DEFAULT '0',
  `egroup3` int(4) NOT NULL DEFAULT '0',
  `egroup4` int(4) NOT NULL DEFAULT '0',
  `egroup5` int(4) NOT NULL DEFAULT '0',
  `egroup6` int(4) NOT NULL DEFAULT '0',
  `egroup7` int(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `managerId` (`managerId`),
  KEY `equipname` (`equipname`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=242 ;

INSERT INTO `topics` (`id`, `managerId`, `equipname`, `pdf`, `comment`, `title`, `url_big`, `url_small`, `egroup1`, `egroup2`, `egroup3`, `egroup4`, `egroup5`, `egroup6`, `egroup7`) VALUES
(220, 38, 'airnailerforbrads', 'airnailerforbradssmall.pdf', 'Read this Air Nailer for Brads instruction sheet.', 'Air Nailer for Brads', 'airnailerforbradsbig.jpg', 'airnailerforbradssmall.jpg', 0, 0, 0, 1, 1, 1, 0),
(219, 38, 'hollowchiselmortiser', 'hollowchiselmortisersmall.pdf', 'Read the Hollow Chisel Mortiser instruction sheet.', 'Hollow Chisel Mortiser', 'hollowchiselmortiserbig.jpg', 'hollowchiselmortisersmall.jpg', 0, 0, 1, 1, 1, 1, 0),
(217, 38, 'woodlathe', 'woodlathesmall.pdf', 'Read the Wood Lathe instruction sheet.', 'Wood Lathe', 'woodlathebig.jpg', 'woodlathesmall.jpg', 0, 1, 1, 1, 1, 1, 0);
(216, 38, 'shaper', 'shapersmall.pdf', 'Read the Shaper instruction sheet.', 'Shaper', 'shaperbig.jpg', 'shapersmall.jpg', 0, 0, 0, 0, 0, 1, 0),
(215, 38, 'jointersurfacercombo', 'jointersurfacercombosmall.pdf', 'Read the Jointer Surfacer Combo instruction sheet.', 'Jointer Surfacer Combo', 'jointersurfacercombobig.jpg', 'jointersurfacercombosmall.jpg', 0, 0, 0, 0, 0, 1, 0),
(214, 38, 'jointer', 'jointersmall.pdf', 'Read the Jointer instruction sheet.', 'Jointer', 'jointerbig.jpg', 'jointersmall.jpg', 0, 0, 0, 0, 0, 1, 0),


CREATE TABLE IF NOT EXISTS `quiz` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `quizId` varchar(255) NOT NULL,
  `quizTitle` varchar(255) NOT NULL,
  `managerId` int(11) NOT NULL,
  `userId` varchar(255) NOT NULL,
  `userGroup` varchar(60) NOT NULL,
  `userScore` float NOT NULL,
  `totalScore` float NOT NULL,
  `passScore` float NOT NULL,
  `passState` tinyint(4) NOT NULL,
  `Result` mediumtext NOT NULL,
  `userDate` date NOT NULL,
  `addDate` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ;

INSERT INTO `quiz` (`id`, `quizId`, `quizTitle`, `managerId`, `userId`, `userGroup`, `userScore`, `totalScore`, `passScore`, `passState`, `Result`, `userDate`, `addDate`) VALUES
(21, '100709143305', 'Saw Scroll Safety Quiz', 38, 'Jack Jones', 'year7', 15, 15, 15, 1, '', '2010-10-18', '2010-10-18 00:00:00'),
(37, '1234567890', 'Random Orbit Sander Safety Quiz', 38, 'Jack Jones', 'Year10', 15, 15, 15, 1, '', '2010-10-24', '0000-00-00 00:00:00'),
(39, '1233234545', 'Bandsaw Safety Quiz', 38, 'Jack Jones', 'Year9', 12, 13, 15, 0, '', '2010-10-20', '2010-10-03 18:47:32');