所以我遇到的问题是,当我将此表单提交到新页面时,如果我只检查一行,那么我发送的数量是正确的。如果我检查并提交多行,则数量将被覆盖,并且两个数量都将打印为最后一个值。我的问题是如何制作它,以便在我能够打印之前不会覆盖数量。
当我尝试将它们作为数组发送时,会发生的是它将为每一行发送一个包含所有数量的数组,包括那些未经检查的数量。
while($result = mysqli_fetch_assoc($runquery))
{
$id = $result['gme_id'];
$title = $result['gme_title'];
$type = $result['gme_type'];
$dateavail = $result['gme_date_avail'];
$price = $result['gme_price'];
echo "<tr>";
echo "<td bgcolor='$color'>$title</td>";
echo "<td>$type</td>";
echo "<td>$id</td>";
echo "<td>$price</td>";
if($dateavail < date('Y-M-D'))
{
echo "<td>
<select name=\"quantity[]\">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>";
echo "<td><input type=\"checkbox\" name=\"selectedgame[]\" value=\"$id\"></td>";
}
else
{
echo "<td>$dateavail</td>";
echo "<td></td>";
}
echo "</tr>";
}
以下是第二页的代码。
$gameid = $_POST["selectedgame"];
foreach($gameid as $value)
{
echo "$value <br />";
$query = "SELECT * FROM gametbl WHERE gme_id = $value";
$runquery = mysqli_query($myCon, $query);
$numrows = mysqli_num_rows($runquery);
while($result = mysqli_fetch_assoc($runquery))
{
$id = $value;
$title = $result['gme_title'];
$price = $result['gme_price'];
$quantity = $_POST['quantity'];
echo "<tr>";
echo "<td>$title</td>";
echo "<td>$id</td>";
echo "<td>$quantity</td>";
echo "<td>$price</td>";
echo "</tr>";
}
}
以下是我得到的结果
当我只在行上检查时:
当我检查了多行时:
感谢任何帮助。我对网页设计还是比较陌生的,我试图从一年前的php课程中重新制作一个项目。我试过联系我那个班级的教授,但我没有得到他的回复,我现在已经通过4个星期前给他发了电子邮件。
答案 0 :(得分:1)
为什么不直接给出关于游戏的数组索引。
<select name=\"quantity[]\">
到
<select name=\"quantity[$id]\">
在你的第二页
$quantity = $_POST['quantity'][$id];
我建议使用支付网关,因为要存储信用卡号,您的网络需要经过审核才能符合PCI标准。