Jump to content

FarahAshikinMohd

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by FarahAshikinMohd

  1. 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 />
×
×
  • 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.