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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.