I am trying to effect a graphic change in a php page depending on the results of a mySQL database query.
<?php
$find_howto=mysql_query("SELECT * FROM `answers` WHERE `username`='$username' AND `pagename`='_I1' ORDER BY `answer` DESC") or die("Error fetching course selection, How To Use The Course");
if(mysql_num_rows($find_howto)>=1)
{
$howto_data=mysql_fetch_assoc($find_howto);
if($howto_data['answer'] == "yes")
{
$count="red";
}elseif($howto_data['answer'] == "visited")
{
$count="yellow";
}
$find_quiz=mysql_query("SELECT * FROM `answers` WHERE `username`='$username' AND `pagename`='_I2' ORDER BY `answer` DESC") or die("Error fetching course selection, Quick Quiz");
if(mysql_num_rows($find_quiz)>=1)
{
$quiz_data=mysql_fetch_assoc($find_quiz);
if($quiz_data['answer'] == "yes")
{
$count="red";
}elseif($quiz_data['answer'] == "visited")
{
$count="yellow";
}
}
if($count == "red")
{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionRed.gif" width="250" height="18"></a></td>';
}elseif($count == "yellow")
{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionYellow.gif" width="250" height="18"></a></td>';
}else{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionGreen.gif" width="250" height="18"></a></td>';
}
?>
If the result of the first query is "yes", then I have given the "count" variable the value "red".
If the result of the first query is "visited", then I have given the "count" variable the value "yellow".
The logic might be right, but the coding errors.
How can I make "if/elseif/else" work above? I've actually got 10 blocks to work with, not just two. But if this works, I can add the rest.
UPDATED SOLUTION: OK. I managed to do it a different way (with a lot of help):
<?php
$find_intro_comp=mysql_query("SELECT * FROM `answers` WHERE `username`='$username' AND (`pagename`='_I1' OR `pagename`='_I2' OR `pagename`='_I3' OR `pagename`='_I4' OR `pagename`='_I5' OR `pagename`='_I6' OR `pagename`='_I7' OR `pagename`='_I8' OR `pagename`='_I9' OR `pagename`='_I10') AND `answer`='yes'") or die("Error pulling intro completed");
if(mysql_num_rows($find_intro_comp)>=10) // the number 10 depends on how many pages there are.
{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionRed.gif" width="250" height="18"></a></td>';
}else{
$find_intro_visit=mysql_query("SELECT * FROM `answers` WHERE `username`='$username' AND (`pagename`='_I1' OR `pagename`='_I2' OR `pagename`='_I3' OR `pagename`='_I4' OR `pagename`='_I5' OR `pagename`='_I6' OR `pagename`='_I7' OR `pagename`='_I8' OR `pagename`='_I9' OR `pagename`='_I10') AND `answer`='visited'") or die("Error pulling intro visited");
if(mysql_num_rows($find_intro_visit)>=1)
{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionYellow.gif" width="250" height="18"></a></td>';
}else{
echo '<img name="Introduction" border="0" src="../img/directories/main/IntroductionGreen.gif" width="250" height="18"></a></td>';
}
}
?>