Jump to content

if and else for exam questions


nade93

Recommended Posts

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

 

 

Link to comment
Share on other sites

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";
	} 
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.