Coding help.

Associate
Joined
22 Aug 2011
Posts
240
I'm not sure how to really execute this, but here's my problem.

Basically, I'm in the final week of my third year project and my e-commerce based PHP project and I need to implement the following feature.

There are going to be three input boxes.

H ['Please enter product height...']
W ['Please enter product width...']
D ['Please enter product depth'...]

The user as situated above needs to enter the height x width x depth of the product that they would like to be calculated.

After they enter those 3 values, there is going to be a calculate button right below that, upon that click, their values are calculated and based upon the result it then processes a result based on my stored values.

The three possible results are going to fall into the following categories:
small, medium or large and based on these three values, there are going to be three prices. small price, medium price and large price.

Any one know what the best way to start is?

I know how to do it in my head, but I can't figure it out coding wise? >.<
 
Associate
Joined
1 Dec 2005
Posts
803
There are a few ways you could do this. Although you could define the boundaries for all of your categories the only one that matters (going by what you've said) is the middle category. Less than the lower bound and it's 'small', greater than the upper bound and it's 'large', and anything else is 'medium'.

Code:
if (result < mediumLower)
  category = small
else if (result > mediumUpper)
  category = large
else
  category = medium
You would need different logic if your rules were different and meant it would be possible for users to calculate a value that fell below a small boundary, or above a large boundary.

Code:
if (result >= smallLower and result < mediumLower)
  category = small
else if (result >= mediumLower and result < largeLower)
  category = medium
else if (result > largeLower and result < largeUpper)
  category = large
else
  category = undefined
Hope that helps.
 
Associate
Joined
25 Jan 2009
Posts
1,342
Location
London
Or OOP way
Code:
class ProductSize {
  const SMALL = 0;
  const MEDIUM = 1000;
  const LARGE = 2000;
  
  public static function getProductSize($theSize) {
    if($theSize >= LARGE) {
      return LARGE;
    } else if ($theSize >= MEDIUM) {
      return MEDIUM;
    } else {
      return SMALL;
    }
  }
}


$pSize = ProductSize::getProductSize(1000);

echo($pSize);

Just modify it to your own requirements
 
Back
Top Bottom