nade93 Posted May 23, 2010 Share Posted May 23, 2010 Hi All I am using php to take data from MYSQL to run a flash xml type of questionaire system however, I am having probelems with if and else for a certain thing ? while ($row = mysql_fetch_assoc($result)) { ?> <item> <question><? echo $row['quest']; ?></question> <answer><? echo $row['answer1']; ?></answer> <answer><? echo $row['answer2']; ?></answer> <answer><? echo $row['answer3']; ?></answer> <answer><? echo $row['answer4']; ?></answer> </item> <? } ?> the code aboveis fine, however i need and if $row correct = answer 4 then code looks like this ? while ($row = mysql_fetch_assoc($result)) { ?> <item> <question><? echo $row['quest']; ?></question> <answer><? echo $row['answer1']; ?></answer> <answer><? echo $row['answer2']; ?></answer> <answer><? echo $row['answer3']; ?></answer> <answer correct="y"><? echo $row['answer4']; ?></answer> </item> <? } ?> with the correct="y" in answer four field. any ideas, tried lots of different way cannot seem to get it Quote Link to comment Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 <answer<?php print ($row['correct'] === $row['answer1']) ? ' correct="y"' : ''; ?>><?php print $row['answer1']; ?></answer> Quote Link to comment Share on other sites More sharing options...
nade93 Posted May 23, 2010 Author Share Posted May 23, 2010 thanks used a similar priciple while ($row = mysql_fetch_assoc($result)) { $correct = $row['correct']; if ($correct == "answer1"){ echo "<item>"; echo "<question>".$row['quest'] ."</question>"; echo "<answer correct=\"y\">".$row['answer1']."</answer>"; echo "<answer>". $row['answer2']."</answer>"; echo "<answer>". $row['answer3'] ."</answer>"; echo "<answer>".$row['answer4'] ."</answer>"; echo "</item>"; } else if ($correct == "answer2"){ echo "<item>"; echo "<question>".$row['quest'] ."</question> <answer>".$row['answer1']."</answer> <answer correct=\"y\">". $row['answer2']."</answer> <answer>". $row['answer3'] ."</answer> <answer>".$row['answer4'] ."</answer> </item>"; } else if ($correct == "answer3"){ echo "<item>"; echo "<question>".$row['quest'] ."</question> <answer>".$row['answer1']."</answer> <answer>". $row['answer2']."</answer> <answer correct=\"y\">". $row['answer3']."</answer> <answer>".$row['answer4'] ."</answer> </item>"; } else if ($correct == "answer4"){ echo "<item>"; echo "<question>".$row['quest'] ."</question> <answer>".$row['answer1']."</answer> <answer>". $row['answer2']."</answer> <answer>". $row['answer3'] ."</answer> <answer correct=\"y\">".$row['answer4'] ."</answer> </item>"; } else{ echo "boo"; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.