Jump to content

Greater than Operator and Multipying a Variable


aeafisme23

Recommended Posts

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

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

?> 

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!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.