php - 从一页到另一页显示 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>
解决方案
请参阅下面的更正代码并尝试一下。
<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>
推荐阅读
- node.js - puppeteer 文件选择器不适合我
- python - 确定有关运行 repo init 的 python 版本的问题
- python - 使用搜索算法(python)到给定点的路线的最近坐标
- powerbi - 计算的度量不适用于 DAX 过滤器
- flutter - 如何在 Flutter 布局中添加或删除组件?
- node.js - Mongodb:我可以比较一个字段中的值是否包含在另一个字段中
- javascript - SyntaxError:位置 1 curl 请求的 JSON 中的意外标记 u
- npm - 无法在 windows10x64 上使用 NPM 安装“node-red-contrib-tf-model”
- android - 从 S3 读取数据以用于移动应用程序 - 仅允许特定域
- typescript - 如何在 TypeScript 中一起使用 for .. of 和 Object.entries