What I have in MySQL table
|seller |product |weight |quantity|
|---------------------------------|
|Jacob |Mobile | 500g | 2 |
|John |Laptop | 3500g | 1 |
|Kiki |Charger | 1000g | |
|Dani |Keyboard| 1500g | 3 |
If one customer orders x2 items from Jacob seller, x1 item from John, and x3 from Dani, then this customer now ordered 6 items with total 9,000 gram weight from 3 sellers.
2 items from jacob = 500 x 2
1 item from John = 3500 x 1
3 items from Dani = 1500 x 3
I want to put these values in php variable
$jacob_items_weight = 500 x 2;
$John_items_weight = 3500 x 1;
$Dani_items_weight = 1500 x 3;
$total_weight_customer_have = 9000;
I already tried using for each loop but I can get only the total weight value, but I want all the above variables so I can use them separately.
The main Aim is to calculate $shipping_price
<?php
if($pro_weight <= 500){
$shipping_price = 10;
}else if($pro_weight <= 1000){
$shipping_price = 15;
}else if($pro_weight <= 2000){
$shipping_price = 25;
}else if($pro_weight <= 3000){
$shipping_price = 35;
}else if($pro_weight <= 4000){
$shipping_price = 45;
}else if($pro_weight <= 5000){
$shipping_price = 55;
}else if($pro_weight <= 6000){
$shipping_price = 62.5;
}else if($pro_weight <= 7000){
$shipping_price = 70;
}else if($pro_weight <= 8000){
$shipping_price = 77.5;
}else if($pro_weight <= 9000){
$shipping_price = 95;
}else if($pro_weight <= 10000){
$shipping_price = 100;
}else{
$shipping_price = 'Sorry We can\'t deliver over 10 KGs';
}
?>
Now
`$shipping_price` of `$jacob_items_weight` (500x 2) is 15 USD.
`$shipping_price` of `$John_items_weight` (3500x 1) is 45 USD.
`$shipping_price` of `$Dani_items_weight ` (1500x 3) is 55 USD.
Now finally I want 15 + 45 + 55 = 115 USD.
$first_seller_shipping_price = 15;
$second_seller_shipping_price = 15;
$third_seller_shipping_price = 15;
$total_shipping_price = 155;
If you get my point if I try to calculate for all 9000 g of items the shipping price will be 95 USD. But due difference in the sellers I have to calculate differently then add them to be 115 like the above. so now instead of 95 the shipping will be 115 USD in total.
How can I achieve this goal?
Thank you for your help.
500g?