Advertisement
gitlez

YA: Grades For Points Input

Sep 9th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. /*
  3.             Yahoo Answers Question: http://answers.yahoo.com/question/index?qid=20110908211514AASeDoS
  4. */
  5.  
  6. $numOfSubjects = 5;
  7. $grades = Array('A' => 50, 'B' => 25, 'C' => 15);
  8.  
  9. if($_SERVER['REQUEST_METHOD'] === 'POST'){
  10.     $points = 0;
  11.     for($i=1;$i<=$numOfSubjects;++$i){
  12.         $points += (int)$_POST[('subject' . $i)];
  13.     }
  14.     echo 'You have ' . $points . ' points.';
  15. }else{
  16.     $dropDowns = '';
  17.     $options = '';
  18.     foreach($grades as $l=>$v){
  19.         $options .= '<option value="' . $v . '">' . $l . '</option>' . PHP_EOL;
  20.     }
  21.     for($i=1;$i<=$numOfSubjects;++$i){
  22.         $dropDowns .= 'Subject ' . $i . ': <select name="subject' . $i . '">' . PHP_EOL . $options . '</select><br>' . PHP_EOL;
  23.     }
  24.     echo 'Please input your grades:<br>' . PHP_EOL . '<form method="post">' . PHP_EOL . $dropDowns . '<input type="submit" value="Calc">' . PHP_EOL . '</form>';
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement