Jump to content

Adding up lots of item's weights


dachshund

Recommended Posts

Hi there,

 

I'm creating a shopping cart and to work out postage cost I need to add all the items weights together.

 

The weight of each item is in the database.

 

I currently have this code:

 


$basket = $_SESSION['basket'];
if ($basket) {
$items = explode(',',$basket);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
foreach ($contents as $id=>$qty) {
$sql = "SELECT * FROM store WHERE id LIKE '$id' AND live LIKE '0'";
$result = mysql_query($sql);
while ($rows = mysql_fetch_array($result))	{
extract($row);

 

so to work out each item's weight I can do $rows['weight'] * $qty.

 

but how could i add all the item's weight together?

 

i hope that makes some sense.

 

thanks,

 

jack

 

 

Link to comment
https://forums.phpfreaks.com/topic/252672-adding-up-lots-of-items-weights/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.