dachshund Posted December 7, 2011 Share Posted December 7, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.