0

シナリオ: 私は大学の出席システムを作成していますが、mysql を更新し、チェックボックスを使用して学生の欠席または出席をマークすることに行き詰まっています。

そのため、現在、表示したいデータをフィルタリングすることができました。これは、student_id、fname、lname、present です。以下のコードをご覧ください

<strong>Class Register:</strong> </br>

<?php

$test3= "SELECT * FROM course_attendance, students, courses, attendance WHERE course_attendance.course_id=courses.course_id AND course_attendance.week_id=attendance.week_number_id AND course_attendance.student_id= students.student_id AND courses.course_id='101' AND attendance.week_number_id='2' ";
$result = mysql_query($test3)  or die(mysql_error());


echo "</br><table border='1' align='center'><tr> <th><strong>Student ID</strong></th> <th><strong>First Name </strong></th> <th><strong>Last Name</strong></th> <th><strong>Present</strong></th> </tr> ";

while($rows=mysql_fetch_array($result)){

    echo "<tr><td width='100' align='center'>" .$rows['student_id'].
"</td><td width='120' align='center'>" .$rows['fname'].
"</td><td width='120' align='center'>" .$rows['lname'].
"</td><td width='120' align='center'>" .$rows['present'].  
"</td><tr width='120' align='center'>";
}
echo "</table>";
?>

したがって、現在、これはデータを示しています:student_id、fname、lname、present.

MySQL のフィールド 'Present' は unsigned tinyint です。これをチェックボックスにして、ユーザーが学生の出席または欠席をマークしてから mysql に更新できるようにしたいと考えています。また、現在のフィールドだけで、学生ID、fname、およびlnameを編集できるようにしたくありません。これは可能ですか?

誰かが私をうまく助けてくれたら、前もって感謝します。私は永遠に感謝します!

4

1 に答える 1

2

このためのフォームにチェックボックスを含めることができます。

<input type='checkbox' class='form' value='Yes' name='checkbox_attendance'/> Present?

次に、そのフィールドの値を確認し、データベースに保存します。

if(isset($_POST['checkbox_attendance']) && $_POST['checkbox_attendance'] == 'Yes') {
    //Store the value of checkbox_attendance (Yes) into the database
} else {
    //Store 'No' into the database
}

Student_id、fname、および lname は、作成しない限り編集できません。インターネット上には PHP フォームに関する多くの情報があります。それらを参照してください。

于 2013-03-12T16:54:10.123 に答える