aeafisme23 Posted April 28, 2010 Share Posted April 28, 2010 This is the code that does not work. I want to create the last greater than in the ELSE statement but it does not work, code works up to that point by erasing the else statement and alternatively I could add 100's of elseif to satisfy a quantity and cost but that is not simplified. I know this is a logical and syntax error on my part but I am not sure how i correctly change it? Any help would be great! Thanks guys or gals! <?php if ( $dvd_quantity == "1" ) { $dvd_cost = "25.00";} elseif ( $dvd_quantity == "2" ) { $dvd_cost = "45.00";} else ( $dvd_quantity > "2" ) { $dvd_cost = "15.00*$dvd_quantity";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/199999-greater-than-operator-and-multipying-a-variable/ Share on other sites More sharing options...
Alex Posted April 28, 2010 Share Posted April 28, 2010 You shouldn't have quotes around it, you don't want a string, you want it to perform the mathematical operation. $dvd_cost = 15.00*$dvd_quantity; Quote Link to comment https://forums.phpfreaks.com/topic/199999-greater-than-operator-and-multipying-a-variable/#findComment-1049713 Share on other sites More sharing options...
litebearer Posted April 28, 2010 Share Posted April 28, 2010 perhaps a switch. psuedo code list price = 25 case qty = 1 net = 1 case qty = 2 net = .9 case qty > 2 net = .6 total sale = list * qty * net -------- is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/199999-greater-than-operator-and-multipying-a-variable/#findComment-1049715 Share on other sites More sharing options...
aeafisme23 Posted April 28, 2010 Author Share Posted April 28, 2010 Thanks for the explaination Alex, makes sense. Unfortunately the page is just white and no error message so it leads me to believe I still have an error in sytnax. Litebearer, thank you for your comment as well. A switch statement may seem more logical but I came across an error as well, it gave me the default error. This is what i tried using your method you suggested: switch ($dvd_cost) { case 1: $dvd_quantity = 1; $dvd_cost = 25.00; break; case 2: $dvd_quantity = 2; $dvd_cost = 40.00; break; case 3: $dvd_quantity > 2; $dvd_cost = 15 * $dvd_quantity; break; default: echo "Sorry we experienced an error"; } a little additional code if it's needed <?php $dvds1 = $_POST["dvds1"]; $dvds2 = $_POST["dvds2"]; $dvds3 = $_POST["dvds3"]; $dvds4 = $_POST["dvds4"]; $dvd_quantity = $dvds1 + $dvds2 + $dvds3 + $dvds4; // QUANTITY if ( $dvd_quantity == "1" ) { $dvd_cost = "25.00";} elseif ( $dvd_quantity == "2" ) { $dvd_cost = "45.00";} else ( $dvd_quantity > "2" ) { $dvd_cost = 15 * $dvd_quantity; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/199999-greater-than-operator-and-multipying-a-variable/#findComment-1049718 Share on other sites More sharing options...
aeafisme23 Posted April 28, 2010 Author Share Posted April 28, 2010 Just wanted to let everyone know I figured it out using an IF statement if ( $dvd_quantity == 1 ) { $dvd_cost = 25.00;} elseif ( $dvd_quantity == 2 ) { $dvd_cost = 45.00;} elseif ( $dvd_quantity > 2 ) { $dvd_cost = ((15 * $dvd_quantity) + 15); } Thanks for letting me get this far so I was able to noodle it in the right direction!!!! Quote Link to comment https://forums.phpfreaks.com/topic/199999-greater-than-operator-and-multipying-a-variable/#findComment-1049727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.