[thelist] Calculating values from field types (PHP + MySQL)
Luther, Ron
Ron.Luther at hp.com
Fri Aug 23 07:01:01 CDT 2002
Hi Dave,
One alternative technique, instead of an "if - then" or "case" statement,
would be to use the product type as a boolean multiplier:
<pseudo code>
ship_cost = 1.50 [Your 'baseline' starting value]
{customer selects another item}
{you hit the database to get availability and item cost and item type}
{now you need to update shipping cost}
ship_cost += (product_type == 'a') + (.5 * (product_type == 'b'))
</pseudo code>
This kind of thing works in languages where "true" defaults to "1" and
"false" defaults to "zero".
HTH,
RonL.
(This should let you keep a running total of shipping costs. Of course,
you're probably looking at arrays or a 2nd db hit to decrement the
shipping cost if you allow them to remove single items from a multi-item cart.)
More information about the thelist
mailing list