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

Link to comment
Share on other sites

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

?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.