473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

online Quize

I am a begnier in php i have some problem in my online quize section, i have 2 pages first one is onlintest.php to fetch questions
Expand|Select|Wrap|Line Numbers
  1. $query="select * from php ";
  2. $row=mysql_query($query) or die ("query failed");
  3. while($result=mysql_fetch_array($row))
  4. {
  5. ?>
  6. <form name="myform" method="post" action="result.php" id="my_form">
  7. <?php echo $result['Q_id'].'&nbsp';?>
  8. <?php echo $result['Question']."<br/><br/>";?>
  9. <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]"  value="(a)" id="radio" />
  10. <?php echo $result['Option_A']."<br/><br/>";?>
  11. <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]"  value="(b)" id="radio" />
  12. php echo $result['Option_B']."<br/><br/>";?>
  13. <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]"  value="(c)" id="radio"/>
  14. <?php echo $result['Option_C']."<br/><br/>";?>
  15. <input type="radio" name="answer[<?php echo $result['Q_id'] ?>]"  value="(d)" /><?php echo $result['Option_D']."<br/><br/>";?>
  16.  
  17. <?php
  18. }
  19. ?>
  20. <input type="submit" class="design" name="cheakresult" value="Submit" />
  21. </form>
second is result.php to show result of user
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['cheakresult'])) {
  2.     $correctAnswers = 0;
  3.     $wrongAnswers = 0;
  4.     $Question = '';
  5.    $totalQuestion=20;
  6.     $idList = join (',', array_map('intval', array_keys($_POST['answer'])));
  7.     $sql = "SELECT Q_id, Question, Option_A,Option_B, Option_C, Option_D, Answer
  8.         FROM PHP_TEST
  9.         WHERE Q_id IN ($idList) ";
  10.     $res = mysql_query($sql) ;
  11.       $qno=1;
  12.  
  13.     while (list($id, $q, $a, $b, $c, $d, $correct) = mysql_fetch_array($res)) {
  14.         if ($correct == $_POST['answer'][$id]) {
  15.             $correctAnswers +=1;
  16.            $img = 'images/success.gif';
  17.            $color='red';
  18.         }
  19.         else {
  20.             $wrongAnswers +=1;
  21.             $img = 'images/fail.gif';
  22.         }
  23.         $Question .= "<tr valign='top'>
  24.             <td>$id.</td>
  25.             <td>$q&nbsp;&nbsp;<img src='$img'><ul><li>$a</li>&nbsp;<li>$b</li>&nbsp;<li>$c</li>&nbsp;<li>$d</li>&nbsp;</ul><div class='ans'>Answer:$correct
  26.             </div></td>
  27.             <td></td>
  28.             </tr>\n";
  29.             $qno +=1;    
  30.     }
  31. }
  32. ?>
  33. <?php
  34. $numberOfQs = $correctAnswers + $wrongAnswers;
  35. $score = round(($correctAnswers / $numberOfQs) * 100);
  36. $leftQuestion=$totalQuestion-$numberOfQs;
  37. echo "Left Questions: $leftQuestion"."<br/>";?>
  38. Correct Answers: <?php echo $correctAnswers; ?> <br>
  39. Wrong Answers: <?php echo $wrongAnswers; ?> <br>
  40. Score: <?php echo $score; ?>
  41.  
now i want if user dosnt attampt any questions and submit the test,then i want to display agian the all questions and thier multiple choice options on result.php and thier answer i have no idea how i can do this..
Jan 28 '14 #1
1 1578
Dormilich
8,658 Expert Mod 8TB
the best would be to check, whether there are the data you expect in the $_POST array, i.e. if $_POST['answer'] is not populated, the user didn’t answer any question.
Jan 29 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.