Garreth 00 Garreth 00 - 6 months ago 11
PHP Question

Issues with if-statement

I have a list like this:

<f:option1>0</f:option1>
<f:option2>50 000</f:option2>
<f:option3>100 000</f:option3>
<f:option4>150 000</f:option4>
<f:option5>200 000</f:option5>
<f:option6>250 000</f:option6>

<f:max_value>150 000</f:max_value>
<f:min_value>0</f:min_value>

<f:value1>1,50</f:value1>
<f:value2>2,00</f:value2>
<f:value3>3,00</f:value3>
<f:value4>4,00</f:value4>
<f:value5>5,00</f:value5>
<f:value6>6,00</f:value6>


This list changes all the time, and I want to write an if-statement to get the correct value

$target_option = 50 000;//Should get me $target_value = 2,00

if (($option6 > 0) && ($option6 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value6;
}elseif (($option5 > 0) && ($option5 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value5;
}elseif (($option4 > 0) && ($option4 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value4;
}elseif (($option3 > 0) && ($option3 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value3;
}elseif (($option2 > 0) && ($option2 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value2;
}elseif (($option1 > 0) && ($option1 <= $target_value) && ($min_value <= $target_value) && ($max_value => $target_value)){
$target_value = $value1;
}


Anyone see what Im doing wrong, or if there is an better way of doing this?

Edit:



Se my complete code here: http://pastebin.com/5pfh4JzF

Edit 2



Found the error on another statement.

Answer

there are 2 errors

1

$target_option = 50 000;

shoud be

$target_option = 50000; // no spaces

2

the last statement of each of them

($max_value => $target_value)

should be

($max_value >= $target_value)

use any Code editors to avoid this kind of errors

http://netbeans.org/downloads/