| 
 Posted by Kimmo Laine on 03/03/07 05:19 
Paul Furman kirjoitti: 
> First, I'm sure the following code is not using an efficient structure  
> for the nested if then else's but I can't recall the right way: 
>  
 
With the help of our friend "else if" you get a really clean code: 
 
if ($item_qty > 19) { 
	$price = ($price * .925); 
	$qty_discount = '20 @ 7.5%'; 
} else if ($item_qty > 9) { 
	$price = ($price * .95); 
	$qty_discount = '10 @ 5%'; 
} else if ($item_qty > 4) { 
        $price = ($price * .975); 
        $qty_discount = '5 @ 2.5%'; 
} 
 
--  
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö 
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
 
[Back to original message] 
 |