Jump to content

Adding variables together Newbie Question...


carbonxps

Recommended Posts

         
         $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...

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.