kikonyc Posted April 3, 2012 Share Posted April 3, 2012 can someone help please... this php is to calculate shipping charges for paypal.. RULES: ($7.00 FOR THE FIRST TWO ITEMS - $1.00 FOR EACH ADDITIONAL ITEM) as is, the formula calculates the number of items - not total of quantity - adds $1 for each additional after 2. any suggestions would be appreciated.. link to form: http://crsecrets.com/test01/order.html FORM LIST ITEMS FORMAT - HTML <TD>Herbal Hair Rejuvenator, Unscented <FONT SIZE="-2">(4oz. jar)</FONT><input type="hidden" name="item_name_1" value="Herbal Hair Rejuvenator, Unscented (4oz. jar)" /> </TD> <TD align="center" id="table"><input name="quantity_1" type="text" value="" size="6" maxlength="2" /></TD> <TD align="center">$13.50<input type="hidden" name="amount_1" value="13.50" /></TD> <?php $products = array(); $url = "?business=*********$handling_cart=7.00"; foreach ($_POST as $k=>$v) { preg_match("/\_(\d{1,3})$/",$k,$match); $key = $match[1]; $products[$key][$k] = $v; } $i=1; foreach ($products as $k=>$v) { if ($v['quantity_'.$k] > 0) { foreach ($v as $k1=>$v1) { $key = explode("_",$k1); switch($key[0]) { case 'item': $var = "item_name_" . $i; break; case 'quantity': $var = "quantity_" . $i; break; case 'amount': $var = "amount_" . $i; break; } //get shipping for additional items above 3 if ($i <= 2) { $shipping = "0.00"; } else { $shipping = "1.00"; } $shipping = ($shipping * $v['quantity_' . $k]); $url .= "&" . $var . "=" . urlencode($v1); } $url .= "&shipping_" . $i . "=" . $shipping; $i++; } } #echo $url; header("Location: https://www.paypal.com/cgi-bin/webscr" . $url); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/260289-can-someone-help-please-need-the-sum-of-all-quantities/ Share on other sites More sharing options...
requinix Posted April 3, 2012 Share Posted April 3, 2012 Since your code isn't really readable in its current state, if (quantity shipping = quantity * 7.00 } else { shipping = 2 * 7.00 + (quantity - 2) * 1.00 } [edit] But now it is. //get shipping for additional items above 3 if ($i $shipping = "0.00"; } else { $shipping = "1.00"; } Fix that. Quote Link to comment https://forums.phpfreaks.com/topic/260289-can-someone-help-please-need-the-sum-of-all-quantities/#findComment-1334125 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.