Forum Moderators: coopster

Message Too Old, No Replies

Shipping price table based on weight

help on deciding ship price from weight

         

nquinn

2:58 pm on May 13, 2004 (gmt 0)

10+ Year Member



Hi all,

I'm wondering if anyone has some sample code on how to calculate a shipping price based on total weight to be shipped.

I am using php/mySQL, and each item has it's own weight in the database.

My question is this: how do you setup a table so that you can check if your $totalweight is between certain weights?

Would it just be something like this?
minweight ¦ maxweight ¦ shipcost

if so, how do you do a proper query to get that shipcost?

I imagine it would be something like this, but I need some help with the syntax.

$result = mysql_query("SELECT shipcost FROM shiptable WHERE $totalweight <= maxweight AND $totalweight >= minweight");

thanks,
Neil

coopster

3:55 pm on May 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are a couple of ways you could do this. First, the way you have it laid out here. Then your query would be something like
SELECT 
shipcost
FROM shiptable
WHERE $totalweight BETWEEN [dev.mysql.com] minweight AND maxweight
;

However, you may only need to store the maximum weight and price and use a different query
SELECT 
shipcost
FROM shiptable
WHERE maxweight >= '$totalweight'
ORDER BY maxweight
LIMIT 1
;

stevenmusumeche

4:00 pm on May 13, 2004 (gmt 0)

10+ Year Member



There is also a free UPS API that allows you to submit weight, dimensions, source zip code, and destination zip code. It will then return a cost to you, which you can markup/markdown in whatever way that fits your business model.

I have used PHP to integrate with the API.