Jump to content

greater than and less than problems php


hellrisisng

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/212746-greater-than-and-less-than-problems-php/
Share on other sites

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

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?

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.

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.