topflight Posted February 12, 2010 Share Posted February 12, 2010 I have 2 variables a nd they are not multiplying. here is what my code looks like: if($rank =='CATI'){$hourly='1,500';}elseif($rank == 'CATII'){$hourly == '2,500';}elseif($rank == 'CATIII'){$hourly == '4,500';}elseif($rank == 'CATIV'){$hourly ='8,000';}elseif($rank =='CATV'){$hourly ='10,000';} $pmoney = $rr["money"]; $money = "$hourly" * "$dur"; $finalcut = "$money" + "$pmoney"; Also the $pmoney is part of a mysql_fetch_assoc but the problem I am having is that $money is not multiplying please help. Thanks in advanced Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/ Share on other sites More sharing options...
jl5501 Posted February 13, 2010 Share Posted February 13, 2010 you have your variables in quotes therefore treated as strings if they are numbers that can be multiplied. remove the quotes Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011577 Share on other sites More sharing options...
JAY6390 Posted February 13, 2010 Share Posted February 13, 2010 does the $money value have any characters other than numbers? Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011578 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 no just numbers Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011582 Share on other sites More sharing options...
JAY6390 Posted February 13, 2010 Share Posted February 13, 2010 Your $hourly figures have , in them. You need to remove those if you want them to work as numbers you can manipulate. PHP sees 1,500 as 1 for example Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011585 Share on other sites More sharing options...
jl5501 Posted February 13, 2010 Share Posted February 13, 2010 ok good So $money = $hourly * $dur; will work Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011586 Share on other sites More sharing options...
JAY6390 Posted February 13, 2010 Share Posted February 13, 2010 The quotes arent an issue echo "5" * "5"; works just fine for example Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011588 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 My current code looks like this if($rank =='CATI'){$hourly='1500';}elseif($rank == 'CATII'){$hourly == '2500';}elseif($rank == 'CATIII'){$hourly == '4500';}elseif($rank == 'CATIV'){$hourly ='8000';}elseif($rank =='CATV'){$hourly ='10000';} $money = $hourly * $dur; $finalcut = $money + $pmoney; And it is still not doing the math correctly I am getting 0 for the $finalcut And just and FYI the dur is a decimal number like 2.5 Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011590 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 any other help please Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011599 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 To troubleshoot what your code is actually doing, echo out the values. For example, if $rank is not one of the strings shown, $hourly will be a null value... Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011605 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 I echo out he rank and it says one of the ranks it is just not multiplying for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011609 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 Ok i troubled shot it and now I test out all the variables but the problem is that $hourly is empty but $rank is not. Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011611 Share on other sites More sharing options...
topflight Posted February 13, 2010 Author Share Posted February 13, 2010 I have tried echoing out the hourly and I get the correct responce but when I echo out: $money = "$hourly" * "$dur"; I get 0 Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011617 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 $dur ? Quote Link to comment https://forums.phpfreaks.com/topic/191926-multiplying-variables/#findComment-1011634 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.