我正在尝试从元素名称基于记录集中的值的表单中检索帖子值。这是表格:
$recordID = $_GET["recordID"];
$colour_result = mysqli_query($con,"SELECT colour_variation.*, colours.* FROM colour_variation INNER JOIN colours ON colour_variation.colour_id=colours.colour_id WHERE product_code='$recordID'");
while($colour_row = mysqli_fetch_array($colour_result))
{
?>
<tr><td valign="middle"><img src="resources/images/colours/<?php echo $colour_row['colour_image']; ?>" width="35" height="35"></td><td width="100"><?php echo $colour_row['colour_name']; ?></td>
<td><center><?php if($colour_row['xs'] !== '') { echo('<input type="text" size="2" name="xs_<?php echo $colour_row[colour_name]; ?>" id="xs_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['s'] !== '') { echo('<input type="text" size="2" name="s_<?php echo $colour_row[colour_name]; ?>" id="s_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['m'] !== '') { echo('<input type="text" size="2" name="m_<?php echo $colour_row[colour_name]; ?>" id="m_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['l'] !== '') { echo('<input type="text" size="2" name="l_<?php echo $colour_row[colour_name]; ?>" id="l_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['xl'] !== '') { echo('<input type="text" size="2" name="xl_<?php echo $colour_row[colour_name]; ?>" id="xl_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['xxl'] !== '') { echo('<input type="text" size="2" name="xxl_<?php echo $colour_row[colour_name]; ?>" id="xxl_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['xxxl'] !== '') { echo('<input type="text" size="2" name="xxxl_<?php echo $colour_row[colour_name]; ?>" id="xxxl_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
<td><center><?php if($colour_row['one_size'] !== '') { echo('<input type="text" size="2" name="one_size_<?php echo $colour_row[colour_name]; ?>" id="one_size_<?php echo $row[colour_name]; ?>" placeholder="Qty">');
} else { echo(''); } ?> </center></td>
</tr>
<?php } ?>
</table>
<input type="hidden" name="product_code" value="<?php echo $row_products['product_code']; ?>" >
我试过这个把它们弄出来,但它不起作用:
<?php
$product_code=$_POST["product_code"];
foreach ($_POST as $key => $value) {
if (substr($key, 0, 2) == "xs_") {
$colour_name[str_replace("xs_", "", $key)] = $value;
}
echo $key;
echo '<br />';
echo $value;
}
?>
每个产品可以有任意数量的颜色。非常感谢您对获得在下一页上显示的值以及每种颜色/尺寸选择的数量的任何帮助。
谢谢