carbonxps Posted March 1, 2012 Share Posted March 1, 2012 $stock_count_attrib1=$db->sp("attrib_stock1"); $stock_count_attrib2=($db->sp("attrib_stock2")); $total_stock_count = ($stock_count_attrib1+$stock_count_attrib2); echo $total_stock_count ; Outputs: 22180 Value of: attrib_stock1 = 22 Value of: attrib_stock2 = 18 I thought the output should be: 40? Please help. Please excuse my newbieness trying to learn... Quote Link to comment https://forums.phpfreaks.com/topic/258037-adding-variables-together-newbie-question/ Share on other sites More sharing options...
trq Posted March 1, 2012 Share Posted March 1, 2012 That code could not produce the results you are describing. Is that the exact code? Quote Link to comment https://forums.phpfreaks.com/topic/258037-adding-variables-together-newbie-question/#findComment-1322703 Share on other sites More sharing options...
carbonxps Posted March 1, 2012 Author Share Posted March 1, 2012 Yes it's exactly like that, It seems to be concatening the two values and adding a zero rather than adding them? $stock_count_attrib1=$db->sp("attrib_stock1"); $stock_count_attrib2=($db->sp("attrib_stock2")); $total_stock_count = ($stock_count_attrib1+$stock_count_attrib2); echo $total_stock_count ; This is pasted from the page. and the results are: 22180 Quote Link to comment https://forums.phpfreaks.com/topic/258037-adding-variables-together-newbie-question/#findComment-1322705 Share on other sites More sharing options...
kicken Posted March 1, 2012 Share Posted March 1, 2012 The only way you'd get a result like that is if $db->sp() is echoing the value, not returning it. If that is the case, it would echo 22, then 18, then your echo $total_stock_count would echo 0 because the other variables would have no value and nothing+nothing=0. Since it would all get echoed right next to each other it'd produce your 22180 number. A quick way to check that would be to: $stock_count_attrib1=$db->sp("attrib_stock1"); echo "<br>--<br>"; $stock_count_attrib2=($db->sp("attrib_stock2")); echo "<br>--<br>"; $total_stock_count = ($stock_count_attrib1+$stock_count_attrib2); echo $total_stock_count ; Those extra echo's would break up the number and you'd get output like: 22 -- 18 -- 0 Quote Link to comment https://forums.phpfreaks.com/topic/258037-adding-variables-together-newbie-question/#findComment-1322707 Share on other sites More sharing options...
carbonxps Posted March 1, 2012 Author Share Posted March 1, 2012 Yes your absolutely correct. I thought: $db->sp("attrib_stock2") was the value from the database, but it does echo... I don't suppose anybody can break down this: $db->sp("attrib_stock2") to explain further? Thanks very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/258037-adding-variables-together-newbie-question/#findComment-1322709 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.