I am new to php mysql so have had difficulty putting this question together. I have a JOIN query which works OK, and everything is fine except that the last echo does not work correctly. The database value of passState can be TRUE/FALSE so its value is always 1 or 0. The page is supposed to display the image filename2.png if the value is 1, or the string 'xxx' if its value is 0. What actually happens is either every row displays the image if ("{$row1['passState']}" == 1)and 'xxx' if set to 0. There are various TRUE/FALSE values in the database, so I think the syntax of the last line is wrong, but I just can't work it out. Any suggestions? <?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 " ";} } ?> Code (markup):
In the while loop add: echo '<pre>'; print_r($row1); echo '</pre>'; PHP: You will be able to see the value of $row1['passState'], and will be able to fix your script easier .
Well that was interesting. There are no values at all for passState, whilst all other values are displayed. This tell me my query must be wrong, because the relevant values are in the database. So can you suggest any reason why there are no passState values?
make sure your query returns any values so do this first $sql="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"; echo $sql; // This will print your query in the screen //copy and paste the query that printed in the screen and run the query in the phpmyadmin or any mysql client and see if it returns any records. exit; /// stop executing further $query1 = mysql_query($sql);