hellrisisng Posted September 7, 2010 Share Posted September 7, 2010 Hi im pritty new to PHP used to using ASP but found PHP to be more resourcful! Anyway, Im trying to work out how to get my script to define if a prduct fee is higher than an available account balance, but hitting brick walls! CODE BELOW: $Credits = 10; $Fee = 5; if ($Fee > $Credits){ //NEED MORE CREDITS }else{ //YOU CAN PURCHASE THIS ITEM } But returns that 10 is not greater than 5, i guess this is because it is only taking the first digit into consideration, even if it is 12 or 15 is still says its not higher than 5 ??? Ive been at it for hours searched google and come up with nothing... please help I may be acting thick and it may be really simple but im lost! Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/ Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Hi there hellrising, $Credits = 10; $Fee = 5; if ($Fee > $Credits){ echo "true"; } else{ echo "false"; } That will always evaluate to false, what you need to work on is (>=) more than equal (<=) less than equal (<>) not equal, just look up comparison operators on php.net: http://php.net/manual/en/language.operators.comparison.php Hope that makes sense... Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/#findComment-1108198 Share on other sites More sharing options...
hellrisisng Posted September 7, 2010 Author Share Posted September 7, 2010 I know what your getting at! Its the number that is the problem ive used greater than and equal too at other times with dates an so forth its just this damd tens not showing as higher than units (10 > 1) its doing my head in. Like if you where to have 152 it would not show higher than 16... Why is this? Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/#findComment-1108202 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 You would need to post your actual code. The only way you could be getting the stated results are if you were comparing the values as strings instead of numbers. Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/#findComment-1108235 Share on other sites More sharing options...
hellrisisng Posted September 7, 2010 Author Share Posted September 7, 2010 thanks for all your help guys, but it was human error (I was not populating on of the arrays)! DEERRRRR lol Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/#findComment-1108236 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 Ummm. What arrays? You have got to checkout all the things that you could be doing wrong BEFORE you run to a programming help forum, especially if you are not going to post the actual code responsible for the symptoms. Quote Link to comment https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/#findComment-1108240 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.