Expand|Select|Wrap|Line Numbers
- $query="select * from php ";
- $row=mysql_query($query) or die ("query failed");
- while($result=mysql_fetch_array($row))
- {
- ?>
- <form name="myform" method="post" action="result.php" id="my_form">
- <?php echo $result['Q_id'].' ';?>
- <?php echo $result['Question']."<br/><br/>";?>
- <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]" value="(a)" id="radio" />
- <?php echo $result['Option_A']."<br/><br/>";?>
- <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]" value="(b)" id="radio" />
- php echo $result['Option_B']."<br/><br/>";?>
- <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]" value="(c)" id="radio"/>
- <?php echo $result['Option_C']."<br/><br/>";?>
- <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]" value="(d)" /><?php echo $result['Option_D']."<br/><br/>";?>
- <?php
- }
- ?>
- <input type="submit" class="design" name="cheakresult" value="Submit" />
- </form>
Expand|Select|Wrap|Line Numbers
- if(isset($_POST['cheakresult'])) {
- $correctAnswers = 0;
- $wrongAnswers = 0;
- $Question = '';
- $totalQuestion=20;
- $idList = join (',', array_map('intval', array_keys($_POST['answer'])));
- $sql = "SELECT Q_id, Question, Option_A,Option_B, Option_C, Option_D, Answer
- FROM PHP_TEST
- WHERE Q_id IN ($idList) ";
- $res = mysql_query($sql) ;
- $qno=1;
- while (list($id, $q, $a, $b, $c, $d, $correct) = mysql_fetch_array($res)) {
- if ($correct == $_POST['answer'][$id]) {
- $correctAnswers +=1;
- $img = 'images/success.gif';
- $color='red';
- }
- else {
- $wrongAnswers +=1;
- $img = 'images/fail.gif';
- }
- $Question .= "<tr valign='top'>
- <td>$id.</td>
- <td>$q <img src='$img'><ul><li>$a</li> <li>$b</li> <li>$c</li> <li>$d</li> </ul><div class='ans'>Answer:$correct
- </div></td>
- <td></td>
- </tr>\n";
- $qno +=1;
- }
- }
- ?>
- <?php
- $numberOfQs = $correctAnswers + $wrongAnswers;
- $score = round(($correctAnswers / $numberOfQs) * 100);
- $leftQuestion=$totalQuestion-$numberOfQs;
- echo "Left Questions: $leftQuestion"."<br/>";?>
- Correct Answers: <?php echo $correctAnswers; ?> <br>
- Wrong Answers: <?php echo $wrongAnswers; ?> <br>
- Score: <?php echo $score; ?>