无法获取多页选择的复选框值


Unable to get checkbox values for multiple page selection

我编写的代码,只需点击Submit按钮,就可以在同一页面上打印所选Book的Book_id。屏幕上显示了多本书,并且可以选择在屏幕上一次最多查看100本书。然而,我不希望看到超过10个。现在,当我选择页面上显示的3、9和7时,它们似乎会在选中复选框时显示出来。但如果我选择1,3,1001243。最后一个从该页面中选择的值,即243打印在屏幕上。这是我的代码

            <form action="more_book_issue.php" method="post">
            <input type="submit" name="submit" Value="Submit"/>
            <?php
            include 'connect_db.php';
            include 'login_check.php';
            include 'check_box_value.php';
            $sql = "select * from Books where id NOT IN (select Book_Id from  Issued)";
            $result = mysqli_query($connection,$sql);

            echo '<table class="table table-hover table-striped" id = "issue-table">
            <thead>
              <tr>
                <th>Id</th>
                <th>Title</th>
                <th>Last Name</th>
                <th>Genre</th>
                <th>Other</th>
                <th>Rate</th>
                <th>Category</th>
                <th>Issue</th>
                <th></th>
              </tr>
            </thead>
            <tbody>';
              while($row = mysqli_fetch_array($result)){
                echo "<tr>
                <th>$row[Id]</th>
                <td>$row[Title]</td>
                <td>$row[Lastname]</td>
                <td>$row[Genre]</td>
                <td>$row[Other]</td>
                <td>$row[Rate]</td>
                <td>$row[Category]</td>
              <td>"
                ?>
            <input type="checkbox" name="addToCart[]" value="<?php echo $row['Id']; ?>"/>
              <?php
                "</td>
              </tr>";
            }
            ?>
            </form>
            <?php

check_box_value.php在这里

<?php
if(isset($_POST['submit'])){
if(!empty($_POST['addToCart'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['addToCart']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
    foreach($_POST['addToCart'] as $selected) {
    echo "<p>".$selected ."</p>";
    }
    echo "<br/><b>Note :</b> <span>Similarily, You Can Also Perform CRUD    Operations using These Selected Values.</span>";
    }
    else{
    echo "<b>Please Select Atleast One Option.</b>";
    }
}
?>

如果我完全理解您的问题,您只需要在$checked_count=count($_POST['addToCart']);之前执行以下代码:

if (sizeof($_POST['addToCart']) > 10) {
    $_POST['addToCart'] = array_slice($_POST['addToCart'], 0, 10);
}