Php 如何在表中添加按钮

Php 如何在表中添加按钮,php,html,sql,Php,Html,Sql,现在我有一个页面,显示老师从数据库中设置的家庭作业。学生必须能够在这一页上看到他们的所有作业,以及截止日期和设定日期。到目前为止,它正在工作,在到期日之后,任务变为红色,这很好。但是,我现在需要添加一个小框或按钮,学生完成任务后可以单击该框或按钮。一旦完成,它将仅为单击它的学生删除它 <?php include_once("connection.php"); //including the database connection file $id= $_GET['i

现在我有一个页面,显示老师从数据库中设置的家庭作业。学生必须能够在这一页上看到他们的所有作业,以及截止日期和设定日期。到目前为止,它正在工作,在到期日之后,任务变为红色,这很好。但是,我现在需要添加一个小框或按钮,学生完成任务后可以单击该框或按钮。一旦完成,它将仅为单击它的学生删除它

    <?php
    include_once("connection.php"); //including the database connection file
    $id= $_GET['id'];
    $result = $conn->prepare("SELECT * FROM homework WHERE class_id=? ORDER BY datedue DESC");
    $result->bind_param("i", $id);
    $result->execute();
    $result2 = $result->get_result();?>
<html>
<head>    
    <title>View IS</title>
</head>
<body>
    <table width='80%' border=0>
        <tr bgcolor='#CCCCCC'>
            <td>Task</td>
            <td>Date Set </td>
            <td>Date Due </td>
            <td><button type="button">Click Me!</button></td>

        </tr>
        <?php
            while($res = mysqli_fetch_array($result2)) {   
                if (strtotime(date("d-m-Y")) > strtotime($res['datedue'])) {
                    echo "<tr style=\"color: red;\">";
                        echo "<td>".$res['description']."</td>";
                        echo "<td>".$res['dateset']."</td>";
                        echo "<td>".$res['datedue']."</td>";
                        echo "<td>".<button type=button>Click Me!</button>."</td>";
                        echo "</tr>";
                } else {
                    echo "<tr>";
                        echo "<td>".$res['description']."</td>";
                        echo "<td>".$res['dateset']."</td>";
                        echo "<td>".$res['datedue']."</td>";
                        echo "<td>".<button type=button>Click Me!</button>."</td>";
                    echo "</tr>";
                }
            }
        ?>
    </table>
</body>
我该怎么做?非常感谢。

我无法测试这个,您能试试看,如果出现错误请告诉我吗

在作业表中创建新字段名“stud_completed”

家庭作业.php页面

taskdone.php页面


一旦完成,它将删除它。如果你这样做,任务将被删除所有学生,那么没有完成任务的学生呢。是的,我的错,这就是我的意思。我将重新编写我的问题。听起来像是用户的一个更新…在这种情况下,我要做的是添加一个额外的列,如student_complete,使用单击的每个学生ID作为数组更新该列。因此,您可以检查数组中是否存在学生ID,并删除家庭作业表loopOK中的该行!!让我在几分钟内给出答案我的会话由于某种原因无法工作,所以我只是将学生ID放在url中,而不是$Log\u student=$\u GET['studid';然后在底部,好的。这将很好,但现在,它只是一个空白页,当我按下任务完成,url变成和它的空白。但是你帮了我很多,从我的评论中很难理解什么不起作用。好啊很乐意帮忙
<?php
        include_once("connection.php"); //including the database connection file
        $id = $_GET['id'];
        $result = $conn->prepare("SELECT * FROM homework WHERE class_id=? ORDER BY datedue DESC");
        $result->bind_param("i", $id);
        $result->execute();
        $result2 = $result->get_result();
        $todayDate = strtotime(date("d-m-Y"));
        $Log_student = $_SESSION['studentID'];
?>
    <html>
    <head>    
        <title>View IS</title>
    </head>
    <body>
        <table width='80%' border=0>
            <tr bgcolor='#CCCCCC'>
                <td>Task</td>
                <td>Date Set </td>
                <td>Date Due </td>
                <td>Action</td>
            </tr>
            <?php
                while($res = mysqli_fetch_array($result2)) {
                    $redDueTask = null; // each loop $redDueTask will be set to NULL
                    $homeworkID = $res['id']; // Get the DueDate of each task
                    $dueDate = strtotime($res['datedue']); // Get the DueDate of each task
                    if ($todayDate > $dueDate) { $redDueTask = 'style="color: red;"'; } // Set $redDueTask if task has past duedate

                    $student_completed = explode(',',$res['stud_completed']); // get the coma seperated completed student list and convert it to array
                    if (!in_array($Log_student, $student_completed)) {  // chk if logged in student ID is in array and if not in the list show task 
            ?>
            <tr <?php echo $redDueTask?>>
                <td><?php echo $res['description']?></td>
                <td><?php echo $res['dateset']?></td>
                <td><?php echo $res['datedue']?></td>
                <td>
                <?php if (isset($redDueTask)) { // $redDueTask will bset if the task duedate has passed, so no need compelete button ?>
                    Time UP!
                <?php } else { // $redDueTask is not set then show compelete button ?>
                    <a href="taskdone.php?tid=<?php echo $homeworkID ?>"><button type='button'>Have Complete</button></a>
                <?php } ?>
                </td>
            </tr>
            <?php
                    }
                }
            ?>
        </table>
    </body>
<?php
                include_once("connection.php"); //including the database connection file
                $tid = $_GET['tid']; // Get Homework Task ID from URL
                $Log_student = $_SESSION['studentID']; // Get Loggedin Student ID from Session

                // Get ROW Statment
                $result = $conn->prepare("SELECT * FROM homework WHERE id=?");
                $result->bind_param('i', $tid);
                $result->execute();
                $result2 = $result->get_result();
                $res = mysqli_fetch_array($result2);        
                $stud_completed = $res['stud_completed']; // Get the current List of completed student
                if ($stud_completed == "") { // If stud_completed is null or blank
                    $stud_completed = $Log_student;  // add the current student ID with out coma
                } else {
                    $stud_completed .= "," . $Log_student;  // Inculde the current logged in student ID with coma
                }

                // Update ROW Statement
                $sql = "UPDATE homework SET stud_completed=? WHERE id=?";
                $stmt = $conn->prepare($sql);
                $stmt->bind_param('i', $stud_completed, $tid);
                if ($stmt->execute()) { 
                    header("homework.php"); // if GOT updated go to home work task list page 
                }
        ?>