我需要将每个值(id)链接到一个用于进行计算的量,但我无法弄清楚这是如何工作的。这是我的代码:
HTML
<select name="type[]">
<option value="id">...</option>
</select>
<input name="amount"/>
//This repeats with a loop 8 times. There are 8 select boxes with the same options.
PHP
$type = $_POST['type'];
$id = $_POST['id'];
$amount = $_POST['amount'];
foreach ($products as $thisProduct) {
foreach ($id as $value) {
if ($thisProduct->getId() == $value) {
$multiply = ($thisProduct->getMultiply($amount));
array_push($array, $multiply);
}
switch($type){
case "one":
$multiplyType = ($thisProduct->getMultiplyType($amount));
array_push($arrayType, $multiplyType);
break;
case "two":
$multiplyType = ($thisProduct->getMultiplyType($amount));
array_push($arrayType, $multiplyType);
break;
case "three":
$multiplyType = ($thisProduct->getMultiplyType($amount));
array_push($arrayType, $multiplyType);
break;
}
}
}
这样可行,但值与上一个<input>
相乘。因此,当上一个input
值= 10时,所有值都会乘以10.将每个input
与特定select
元素相关联的最简单方法是什么?