PHPNS Posted April 10, 2007 Share Posted April 10, 2007 Hi All! My first post here. I'm trying to make a custom shipping cost calculator where the calculator finds each row(item and quantity) from a shopping cart table, but I'm stuck on the loop. As it is so far I've been able to create the code so that it finds each item in the cart and weight(s), however I need a secondary loop (I think?) that adds each fetched row's weight together as a total weight. Understand?? Here's a snippet of what I have: while ($row = mysql_fetch_assoc($result)) { $weight = $row['pd_weight'] * $row['ct_qty']; } So basically this code will output each products weight, as seperate rows. Can someone help me add a loop in here that will add each row together, afterwards, as a total weight?? I'm relatively new to programming and the loops get me everytime. Please help!! Link to comment https://forums.phpfreaks.com/topic/46472-solved-loop/ Share on other sites More sharing options...
kenrbnsn Posted April 10, 2007 Share Posted April 10, 2007 Just add the computed weight to the total weight in the loop <?php $total_weight = 0; while ($row = mysql_fetch_assoc($result)) { $weight = $row['pd_weight'] * $row['ct_qty']; $total_weight += $weight; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/46472-solved-loop/#findComment-226075 Share on other sites More sharing options...
PHPNS Posted April 10, 2007 Author Share Posted April 10, 2007 Thank you VERY much Ken. It worked!!!! (as you probably knew it would). You're a life saver! Cheers. Bill Link to comment https://forums.phpfreaks.com/topic/46472-solved-loop/#findComment-226082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.