Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Yahoo Answers Question: http://answers.yahoo.com/question/index?qid=20110908211514AASeDoS
- */
- $numOfSubjects = 5;
- $grades = Array('A' => 50, 'B' => 25, 'C' => 15);
- if($_SERVER['REQUEST_METHOD'] === 'POST'){
- $points = 0;
- for($i=1;$i<=$numOfSubjects;++$i){
- $points += (int)$_POST[('subject' . $i)];
- }
- echo 'You have ' . $points . ' points.';
- }else{
- $dropDowns = '';
- $options = '';
- foreach($grades as $l=>$v){
- $options .= '<option value="' . $v . '">' . $l . '</option>' . PHP_EOL;
- }
- for($i=1;$i<=$numOfSubjects;++$i){
- $dropDowns .= 'Subject ' . $i . ': <select name="subject' . $i . '">' . PHP_EOL . $options . '</select><br>' . PHP_EOL;
- }
- echo 'Please input your grades:<br>' . PHP_EOL . '<form method="post">' . PHP_EOL . $dropDowns . '<input type="submit" value="Calc">' . PHP_EOL . '</form>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement