首页 > 解决方案 > 从一页到另一页显示 db 的检查值

问题描述

我从数据库中获取数据并用复选框将其显示在表格中,现在我想将一页的选中行显示到另一页的表格中。我在另一页上的代码无法正常工作并且不显示数据。

这是获取数据并在第一页带有复选框的表格中显示的代码。

<form method="post" action="other.php">
    <table  border="2px" align="center">
        <tr >
            <th width="100">ID</th>
            <th width="200">Item</th>
            <th width="100">Price</th>
            <th  width="200"></th>
        </tr>
        <?php
            $conn=mysqli_connect("localhost","root","","hotal");
            if($conn-> connect_error){
                die("Connection field:". $conn-> connection_error);
            }
            $sql="SELECT id,item,price from beverages";
            $result=$conn->query($sql);

            if($result->num_rows>0){
                while($row=$result->fetch_assoc()){
                echo"<tr><td>".$row["id"]."</td><td>".$row["item"]."</td> 
                <td>".$row["price"]."</td><td>"."<input type='checkbox' name='menu[]' 
                value=>".$row["item"]."</td></tr>"; 
            }
            echo"</table>"; }else {
            echo"0 result"; }
            $conn->close();
        ?>
    </table>
    <input type="submit" value="submit" />
</form>

这是第二页的代码,我想在表格中显示第一页的检查值

<table  border="2px" align="center">
    <tr >
        <th width="100">ID</th> 
        <th width="200">Item</th>
        <th width="100">Price</th>
    </tr>
    <?php 
        $name=$_POST['menu'];
        foreach ($name as $row) {
            echo"<tr><td>".$row."</td><td>".$row."</td><td>".$row."</td></tr>";
        }
    ?>
</table>

标签: phphtml

解决方案


请参阅下面的更正代码并尝试一下。

<form method="post" action="other.php">
    <table  border="2px" align="center">
        <tr >
            <th width="100">ID</th>
            <th width="200">Item</th>
            <th width="100">Price</th>
            <th  width="200"></th>
        </tr>
        <?php
            $conn=mysqli_connect("localhost","root","","hotal");
            if($conn-> connect_error){
                die("Connection field:". $conn-> connection_error);
            }
            $sql="SELECT id,item,price from beverages";
            $result=$conn->query($sql);

            if($result->num_rows>0){
                while($row=$result->fetch_assoc()){
                $values = $row["id"].'|'.$row["item"].'|'.$row["price"];
                echo"<tr><td>".$row["id"]."</td><td>".$row["item"]."</td> 
                <td>".$row["price"]."</td><td>"."<input type='checkbox' name='menu[]' 
                value=".$values."></td></tr>"; 
            }
            echo"</table>"; }else {
            echo"0 result"; }
            $conn->close();
        ?>
    </table>
    <input type="submit" value="submit" />
</form>

现在要获取 ID、项目和价格使用爆炸,您可以在下面看到。

第二页:

<table  border="2px" align="center">
    <tr >
        <th width="100">ID</th> 
        <th width="200">Item</th>
        <th width="100">Price</th>
    </tr>
    <?php 
        $name=$_POST['menu'];
        foreach ($name as $row) {
            $values = explode("|",$row);
            echo"<tr><td>".$values[0]."</td><td>".$values[1]."</td><td>".$values[2]."</td></tr>";
        }
    ?>
</table>

推荐阅读