Link to home
Start Free TrialLog in
Avatar of Steve-UK
Steve-UKFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Always prefer a greater value using IF Statements

Hello,

I'm after a bit of help with a script I have written, I'm pretty new to PHP and struggling to get my head around it.

I have a website which uses a shipping calculator, featuring the dimensions (width, length, height) and the weight (in kg) of a parcel.
I'm using 2 variables; $volumetric and $weight.
The $volumetric variable is calculated as such, (weight * length * height) / 5000.

Here's what the script is intended to do:-
1. Get values from an HTML form. In this case, 'volumetric' and 'weight'.
2. Compare the values to see which is the largest.
3. Return/redirect to the corresponding URL of the product from the web shop.

At the moment it always takes preference to the volumetric value and does not take the weight into consideration.

An example would be as follows:
Customer enters their dimensions of their box size, 10cm x 10cm x 10cm. This works out to be a volumetric weight value of 0.2KG.
If the customer enters the weight for their parcel as say 5KG, it should return the product for 5KG.

Essentially what I'm trying to do is return/redirect to the URL of a product which has the greater value. I'm currently using IF statements to do this, however, I'm always open to suggestions!

I have attached the code for your reference.

Many Thanks in advance for your reply.

Ben M. fetchProduct.php fetchProduct.php
SOLUTION
Avatar of Scott Madeira
Scott Madeira
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Amick
Amick
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There is at least one typo in my previous post.  Line 16 should be changed from "($weight >= $volumetric) {" to simply "{" .
Avatar of Steve-UK

ASKER

Hi guys,

Many thanks for the responses, much appreciated.

I have tried both versions so far and for some reason both are returning the 'Invalid' page no matter what values are entered.

The quote form for testing can be found at http://79.170.44.122/parcelsave.com/pages.php?pageid=19

Looks to me like either method should work, but looks like it's going wrong somewhere.

Thanks again,
Ben
Hi again,

Ignore my last post...managed to get it working!

Just added a couple of braces in the right place.

All that's left is to add an upper limit.

Thank you both very much for all your help.

Regards,
Ben