0

I need to link each value(id) to an amount for making some calculations but I can't figure out how this could work. This is my code:

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;
        }
    }
}

This works but the values get multiplied with the last <input>. So when the last input value = 10, all the values get multiplied by 10. What is the simplest way to link each input to a specific select element?

1 Answer 1

0

Turn your text-input also in to an array. Take a look at this answer for more information: put input type text in an array

Sign up to request clarification or add additional context in comments.

1 Comment

Tried it before and added a foreach to iterate through these but didn't work out...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.