多个复选框仅显示1个值

时间:2015-09-30 04:01:16

标签: php sql

当选中一个复选框时,它应该在下一个php文件中生成一个时间字段,但该页面只生成1个选中的复选框而不是全部。

<html>
<head>
    <style>
            table {
            border-collapse: collapse;

        }
        table, td, th {
            border: 1px solid gray;
        }

        table {
            width: 80%;
        }

        th {
            height: 30px;
        }
    </style>
    <script type ="text/javascript">

        function load() {
            if (!document.getElementById('checkbox1').checked) {
                return document.getElementById('show').innerHTML = '';
            }
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
            } else {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            }

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById('show').innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open('GET', 'include.inc.php', true);
            xmlhttp.send();
        }

    </script>
</head>
<body>
    <p><?php include 'header.php'; ?></p>
    <div align="justify">


        <td><form method="post" action="search.php">
                Name:&nbsp;<input type="text" name="search" />
                <input type="submit" name="submit" value="Search">
            </form></td>


        <td><form method="post" action="grouprank.php">
                Rank:&nbsp;<input type="text" name="groupby" />
                <input type="submit" name="submit" value="Group by">
            </form></td>

        <?php
        require ("dbfunction.php");
        $con = getDbConnect();
        ?>





        <td>&nbsp;

        <td>&nbsp;<input type="checkbox" id ='checkbox1' name="checkbox1" onclick="load();" value="Bike">Include previous service terms</td>  <!-- database -->
    </div>
    <form name="form" id="form" action="multiedit.php" method="post">
    <div id="show">        
    </div>
    <p><table>
        <tr>
            <th>Tick</th>
            <th>Name</th>
            <th>Rank</th>
            <th>Start Date</th>
            <th>End Date</th>
            <th>Watchkeeping</th>
            <th>Active</th>
        </tr> <!-- database -->
        <tr>
            <?php
            if (!mysqli_connect_errno($con)) {

                $queryStr = "SELECT * " .
                        "FROM crewlist";
            }
            $result = mysqli_query($con, $queryStr);
            while ($row = mysqli_fetch_array($result)) {
                if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {

                    echo "<tr><th>" . "<input type = \"checkbox\" id ='checkbox2' name = 'checkbox2' value=\"".$row['crew_id']."\" >" . "</th>";
                    echo "<th>" . "<a href=\"viewcrew.php?id=" . $row['crew_id'] . "\">" . $row["crew_name"] . "</a>";
                    echo "<th>" . $row["crew_rank"] . "</th>";
                    echo "<th>" . $row["start_date"] . "</th>";
                    echo "<th>" . $row["end_date"] . "</th>";
                    echo "<th>" . $row["watchkeeping"] . "</th>";
                    echo "<th>" . $row["active"] . "</th>";
                } else {

                }

            }

            ?>

        </tr>
        <input type="submit" value="Submit" ></td>
        </tr>

    </table>
    </form>
</body>

这是下一页

<?php include 'header.php'; ?>

<div id="container4"><?php


require ("dbfunction.php");
$con = getDbConnect();
$checkbox2 = $_POST['checkbox2'];
if (!mysqli_connect_errno($con)) {

$queryStr = "SELECT * " .
        "FROM crewlist WHERE crew_id =".$_POST['checkbox2'];
 }
 $result = mysqli_query($con, $queryStr);
 print_r($_POST);
 while ($row = mysqli_fetch_array($result)) {

if (date("Y-m-d") > $row['start_date'] && date("Y-m-d") < $row['end_date']) {

    echo "<tr><th>" . $row["crew_name"] . ":</th><br>";
    echo "                    <tr>
                    <td>Shift 1:</td>
                    <td><input type=\"time\" name=\"start_hour\" value=\"start_hour\" id=\"start_hour\" step=\"1800\" required> to <input type=\"time\" name=\"end_hour\" value=\"end_hour\" id=\"end_hour\" step=\"1800\" required>
                    </td>       
                </tr>
                <tr>
                    <td>Shift 2:</td>
                    <td><input type=\"time\" name=\"start_hour2\" value=\"start_hour2\" id=\"start_hour2\" step=\"1800\" required> to <input type=\"time\" name=\"end_hour2\" value=\"end_hour2\" id=\"end_hour2\" step=\"1800\" required>
                    </td>       
                </tr><br><br>";
} else {

}
 }
 ?>

我尝试过运行foreach循环但是括号中似乎存在语法错误

0 个答案:

没有答案