1

我有一些小错误,想知道是否有人可以提供帮助!

我正在为一所大学创建一个考勤系统。

这个场景:

学生成功登录,然后想要查看他/她对特定课程的出勤率。

问题:我希望它显示来自 mysql 的已检查和未检查数据,它当前显示一个空复选框(当它意味着要检查时)同时它显示大量重复数据,是否有可能我可以限制它,比如说例如每周显示一条记录,它显示所有数据并复制它。

<?php

$q3= "SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes
 FROM courses, course_attendance, attendance, students
WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'  
 ";


$result = mysql_query($q3)  or die(mysql_error());

echo "<table border='1' align='center'><tr>  <th><strong>Week Number</strong></th> <th><strong>Present</strong></th> <th><strong>Notes</strong></th>  </tr> ";
while($row = mysql_fetch_assoc($result))
{
    extract($row);
echo 

"</td><td  width='200' align='center'>" .$row['week_number'].
"</td><td  width='400' align='center'><input type='checkbox' name='present'" .$row['present']. 
"</td><td  width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";
?>

注意:我已成功连接到数据库,mysql 已启动并正在运行,我正在使用会话,目前它确实显示学生的数据但不显示现有的选中或未选中值,复选框为空。

谁能帮忙

4

3 回答 3

0

在您的代码中,您没有正确定义要检查的复选框。checked="true"如果“当前”字段为 1 ,则创建一个添加代码。

<?php

    $q3 = " SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes 
            FROM courses, course_attendance, attendance, students
            WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'";


    $result = mysql_query($q3) or die(mysql_error());

    echo "
        <table border='1' align='center'>
            <tr>
                <th><strong>Week Number</strong></th>
                <th><strong>Present</strong></th> 
                <th><strong>Notes</strong></th>  
            </tr>
        ";

    while($row = mysql_fetch_assoc($result)) {
        $checked = '';
        if($row['present'] == 1) {
            $checked = ' checked="true"';
        }

        echo "
            <tr>
                <td width='200' align='center'>" . $row['week_number'] . "</td>
                <td width='400' align='center'>
                    <input type='checkbox' name='present'" .$checked . "/>
                </td>
                <td width='400' align='center'>" . $row['notes'] . "</td>
            </tr>
        ";
    }

    echo "</table>";

?>
于 2013-03-17T18:05:46.850 回答
0

您的

echo 
    "</td><td  width='200' align='center'>" .$row['week_number'].
    "</td><td  width='400' align='center'><input type='checkbox' name='present'" .$row['present']. 
    "</td><td  width='400' align='center'>" .$row['notes'].
    "</td><tr>";

声明应该是

$present = "";
if(.$row['present']==1)
{
   $present = "checked =checked/>";    
}
else
{
   $present = "/>";    
 }

echo "" .$row['week_number']。"" .$row['notes']。"";

希望这对您有所帮助。谢谢

于 2013-03-17T18:07:19.777 回答
0
$checked = '';
if($present == 1) {
    $checked = 'checked="checked"';
}

echo "</td><td  width='200' align='center'>" .$row['week_number'].
"</td><td  width='400' align='center'><input type='checkbox' name='present'" .$checked . "/>" . 
"</td><td  width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";

尝试。

于 2013-03-17T18:35:58.897 回答