dongweicha6077 2015-12-08 23:10
浏览 6
已采纳

创建一个用户输入字母等级[关闭]的表单

So I need to create a simple form where the user inputs a letter great in the text box, grades from A, B, C, D, or F and then gets a display saying a certain sentence.

<html>
<head>
    <title>Letter Grades</title>
</head>
<body>
    <form action="LetterGrades.php" method="get" >
        <p>Grade: <input type="text" name="grade" />
        <input type="submit" /></p>
    </form>
</body>
</html>

Of course using the $_GET method. Can anyone help out? Stuck at work with 1 other worker so I'm short staff.

  • 写回答

1条回答 默认 最新

  • dtslobe4694 2015-12-08 23:25
    关注

    Easy. Make an array containing sentences with the index being the grade.

    $grade_sentences = array(
        'A' => 'Great Job!',
        'B' => 'Good Job!',
        'C' => 'Not bad!',
        'D' => 'Could use a little work',
        'F' => 'I\'ve seen worse'
    );
    

    Then check if the array key exists and return the associated sentence.

    if(array_key_exists($_GET['grade'], $grade_sentences)){
        echo $grade_sentences[$_GET['grade']];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?