File manager - Edit - /home/kridsana/webapp.cm.in.th/663012801/u66301280010/P002/index.php
Back
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // รับค่าคะแนนจากฟอร์ม $spirit = isset($_POST['spirit']) ? intval($_POST['spirit']) : 0; $test = isset($_POST['test']) ? intval($_POST['test']) : 0; $assignment = isset($_POST['assignment']) ? intval($_POST['assignment']) : 0; $finalExam = isset($_POST['final_exam']) ? intval($_POST['final_exam']) : 0; // คำนวณคะแนนรวม $totalScore = $spirit + $test + $assignment + $finalExam; // กำหนดเกรดตามคะแนนรวม $grade = ''; if ($totalScore >= 80) { $grade = 'A'; } elseif ($totalScore >= 75) { $grade = 'B+'; } elseif ($totalScore >= 70) { $grade = 'B'; } elseif ($totalScore >= 65) { $grade = 'C+'; } elseif ($totalScore >= 60) { $grade = 'C'; } elseif ($totalScore >= 55) { $grade = 'D+'; } elseif ($totalScore >= 50) { $grade = 'D'; } else { $grade = 'F'; } // แสดงผลลัพธ์ $result = [ 'spirit' => $spirit, 'test' => $test, 'assignment' => $assignment, 'finalExam' => $finalExam, 'totalScore' => $totalScore, 'grade' => $grade ]; } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>P002 ระบบประมวลผลเกรด PHP</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #b9ff9f; } .form-container { background-color: #3bdf00; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); max-width: 700px; margin: auto; } h2 { text-align: center; } h4 { text-align: center; } table { width: 100%; margin-bottom: 20px; } table td { padding: 10px; text-align: left; } table input { width: 100%; padding: 8px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; } .form-group { text-align: center; } .form-group input[type="submit"] { background-color: #2a8205; color: white; border: none; cursor: pointer; font-size: 18px; } .form-group input[type="submit"]:hover { background-color: #45a049; } .result { margin-top: 20px; padding: 15px; background-color: #eef2f3; border: 1px solid #ccc; border-radius: 8px; text-align: center; font-size: 18px; } .result h3 { margin: 0; } .result p { margin: 10px 0; } </style> </head> <body> <div class="form-container"> <h2>ระบบประมวลผล Grade</h2> <form id="gradeForm" method="POST"> <table> <tr> <td><label for="spirit">จิตพิสัย :</label></td> <td><input type="number" id="spirit" name="spirit" min="0" max="20" required></td> <td><label>คะแนน</label></td> </tr> <tr> <td><label for="test">แบบทดสอบ :</label></td> <td><input type="number" id="test" name="test" min="0" max="30" required></td> <td><label>คะแนน</label></td> </tr> <tr> <td><label for="assignment">งาน :</label></td> <td><input type="number" id="assignment" name="assignment" min="0" max="20" required></td> <td><label>คะแนน</label></td> </tr> <tr> <td><label for="final_exam">สอบปลายภาค :</label></td> <td><input type="number" id="final_exam" name="final_exam" min="0" max="30" required></td> <td><label>คะแนน</label></td> </tr> </table> <div class="form-group"> <input type="submit" value="คำนวณเกรด"> </div> </form> <?php if (isset($result)): ?> <!-- แสดงผลคะแนนรวมและเกรด --> <div id="result" class="result"> <h3>ผลการคำนวณเกรด</h3> <p>จิตพิสัย: <?php echo $result['spirit']; ?> คะแนน</p> <p>แบบทดสอบ: <?php echo $result['test']; ?> คะแนน</p> <p>งาน: <?php echo $result['assignment']; ?> คะแนน</p> <p>สอบปลายภาค: <?php echo $result['finalExam']; ?> คะแนน</p> <hr> <p>คะแนนรวม: <?php echo $result['totalScore']; ?> คะแนน</p> <p>เกรดที่ได้รับ: <?php echo $result['grade']; ?></p> </div> <?php endif; ?> </div> <h4>นายธนกฤต สอนเขื่อน 010</h4> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.86 |
proxy
|
phpinfo
|
Settings