timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 Each radio button has a different name now, hence me using list on the billingInfo page Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715409 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 OK now change the code back to what you had when you first posted so we get a value instead of "Array" being shown so we can try it again. Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715413 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 done It's back to getting 0 for a total Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715415 Share on other sites More sharing options...
Mad Mick Posted December 14, 2008 Share Posted December 14, 2008 Can you do a print_r on $_POST['package_'] so we can see exactly what is being processed. I just tried: <?php $package=array("bread"=>"89.99,wed","cheese"=>"30.00,fri"); $total=0; while (list ($name,$val) = @each ($package)) { $raw = "$val"; $price = explode(",", $raw); $total += $price[0]; } echo $total; ?> which from your earlier comments is what i think the structure of $_POST['package_'] would give and I get the correct total. Thats why i think your while loop is actually ok and there is another problem... Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715418 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 OK now before you add the values together - get rid of that $ symbol from the value THEN add them together. $val=substr($val,1); Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715420 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 I see why Mad Mick's is working - he's not using that $ symbol in his! Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715421 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 Yesideez, You are my hero! This is the final code while (list ($name,$val) = @each ($_POST['package_'])) { $val=substr($val,1); $price = explode(",", $val); $tmp = $price[0]; $total += $tmp; And it gives me a total now Thank you so much for your patience Mad Mick, thank you for your help as well, but the $_POST['package_'] has always worked ok Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715427 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 When you add numbers together the $ counts as non-numerical and will always return a value of 0. Glad it now works Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715429 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 This might be safer... while (list ($name,$val) = @each ($_POST['package_'])) { $price = explode(",", $val); $total += substr($price[0],1); Give it a whirl and see... Where you had it before it was stripping the first character off each element in the array and the display looks a bit strange with the first character missing. Link to comment https://forums.phpfreaks.com/topic/136969-val-addition/page/2/#findComment-715431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.