trampolinejoe Posted November 28, 2008 Share Posted November 28, 2008 Hello you great people, The code below is meant to display a product and a name. for example. keyboard $100 mouse $20 LCD $250 Then a total: $370 But its currently outputting keyboard $100 mouse $20 LCD $250 Then a total: $250 (what ever the last product on the list is) $i = 0; while($i < sizeof($prices)){ echo getProduct($products[$i]); echo " $"; echo getProductPrice($prices[$i]); $productPrice = getProductPrice($prices[$i]); $totalProductPrice = $productPrice + TotalProductPrice; echo " \n"; $i++; } echo "$totalProductPrice"; Please help. Link to comment https://forums.phpfreaks.com/topic/134586-solved-for-loop-not-summing-up/ Share on other sites More sharing options...
kenrbnsn Posted November 28, 2008 Share Posted November 28, 2008 Can you show us the functions getProduct & getProductPrice and the contents of each array -- $products & $prices? Ken Link to comment https://forums.phpfreaks.com/topic/134586-solved-for-loop-not-summing-up/#findComment-700769 Share on other sites More sharing options...
DarkWater Posted November 28, 2008 Share Posted November 28, 2008 Tell me what you see wrong with this line: $totalProductPrice = $productPrice + TotalProductPrice; Link to comment https://forums.phpfreaks.com/topic/134586-solved-for-loop-not-summing-up/#findComment-700771 Share on other sites More sharing options...
zenag Posted November 28, 2008 Share Posted November 28, 2008 $totalProductPrice[] = $productPrice + TotalProductPrice; } print_r($totalProductPrice); Link to comment https://forums.phpfreaks.com/topic/134586-solved-for-loop-not-summing-up/#findComment-700772 Share on other sites More sharing options...
trampolinejoe Posted November 28, 2008 Author Share Posted November 28, 2008 Thanks for your help guys, it works now Link to comment https://forums.phpfreaks.com/topic/134586-solved-for-loop-not-summing-up/#findComment-700777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.