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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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); Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.