Jump to content

Multiple choice quiz


FarahAshikinMohd

Recommended Posts

Hi everyone, this is my first post here. I need some help with a PHP/MySQL multiple choice quiz that I'm making for a website. I have succesfully created a CMS to create new quizzes and then add questions and answers for it to a MySQL database table. i already create a database for question and answer. then i want to display the result where the user can see the correct answer.if the user answer it correctly it will show green color in correct answer if not it will show red. (im sorry for my broken english. ) this is the code

<?php


if (isset($_POST['cid']))    
{    
          $title_id = $_POST['cid'];




}  else{
$title_id = "";
}
$query="SELECT * FROM elearning_question WHERE title_id='$title_id'";
$q=mysql_query($query);  
?>


<br />
  <h3><center>Answer List</h3>
<table border = "1" width="90%" style="background-color:#FFFFFF; border-collapse:collapse; table-layout:fixed" align="center" cellpadding="5" cellspacing="3">
 <tr bgcolor="#00FFFF">
    <th width="6%">Bil</th>
       <th width="50%">Question</th>


</tr>
<?php
$count=1;
while($row=mysql_fetch_array($q))
{
if ( $row['question_type'] == '1')
{
?> 




   <tr>
<td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>
     
<td><?php echo $row['question']; ?></td>
</tr> 


<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">A.<?php echo $row['answer_one']; ?></td>
<?php } 
else 
{?>
<td width="15%">A.<?php echo $row['answer_one']; ?></td>


<?php } ?>
</tr>


<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">B.<?php echo $row['answer_two']; ?></td>
<?php } 
else 
{?>
<td width="15%">B.<?php echo $row['answer_two']; ?></td>
<?php } ?>
</tr>
<?php }




else if ($row['question_type'] == '2')
{
?>




    <tr>
<td align="center"><input name="id"  type="hidden" value="bil"> <?php echo $count; ?></td>
     
<td><?php echo $row['question']; ?></td>
</tr> 
<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">A.<?php echo $row['answer_one']; ?></td>
<?php } 
else 
{?>
<td width="15%">A.<?php echo $row['answer_one']; ?></td>
<?php } ?>
</tr>


<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">B.<?php echo $row['answer_two']; ?></td>
<?php } 
else 
{?>
<td width="15%">B.<?php echo $row['answer_two']; ?></td>
<?php } ?>
</tr>


<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">C.<?php echo $row['answer_three']; ?></td>
<?php } 
else 
{?>
<td  width="15%">C.<?php echo $row['answer_three']; ?></td>
<?php } ?>
</tr>


<tr>
<td></td>
<?php if ($row['correct_answer']=='group') 
{?>
<td style="color:#009900" width="15%">D.<?php echo $row['answer_four']; ?></td>
<?php } 
else 
{?>
<td width="15%">D.<?php echo $row['answer_four']; ?></td>
<?php } ?>
</tr>




<?php
}
$count++;}
?>
  </table>
  <br />
Edited by Barand
add code tags
Link to comment
Share on other sites

1. Do not hijack old threads. I have moved your post to a new topic.

2. Use code tags around your code (use the <> button in the toolbar)

 

I cannot see from your code how you know what answer the user gave, so that you can see if it is correct or not. In fact, with its confusing mix of html and php,  lack of indentation plus repetitive code, it's not easy to see anything.

 

What is the significance of "correct_answer" having the value "group"?

 

And finally, what is your question?

  • Like 1
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.