Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Is there a way to compare numbers like if 0.85 > 0.65 then

Quote Reply
Is there a way to compare numbers like if 0.85 > 0.65 then
I'm wondering if there is a simple built in way to compare numbers that appear in columns in the database.

For example, I've got two fields, one is user inputed as #.## (where # is obviously a number), then I've got another field from a second table that is also #.## (not user inputed).

When it comes to the detailed.html template I'd like to compare these two numbers and if the user inputed number is lower then print it out in green, if it's higher than the second number then print it out in red.

Something like this maybe:
Code:

<%if card1price > get_value_prices($cardname1)%><font color="red"><%card1price%></font><%else%><font color="green"><%card1price%></font><%endif%>


I'm not sure what actually goes in the place of the ">" between card1price and get_value_prices to try to figure out if the first value is greater than the second value, or if it's even possible.

Any questions please ask.

Thanks you know who for all the help. Wink

Last edited by:

Westin: May 8, 2009, 8:36 PM
Quote Reply
Re: [Westin] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
I would imagine, what you need is:

<%set the_price_got = get_value_prices($cardname1)%>
<%if card1price > the_price_got%>
. ..
<%endif%>

The reason you have to do it like that, is cos the globals are not processed before the comparison, so it will always return false otherwise

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
Hmmm, this is what I put in:

Code:
<%set the_price_got = get_value_prices($cardname6)%><%if card6price > the_price_got%><font color="red"><%card6price%></font><%else%><font color="green"><%card6price%><%endif%>

Do you see anything wrong with that bit of coding?

For some reason the result always comes up with the red text even when the <%card6price%> is less than <%the_price_got%>

The numbers are stored as #.## in both cases.
Quote Reply
Re: [Westin] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
Okay, I think this is the correct way to write it:
Code:
<%set the_price_got = get_value_prices($cardname1)%><%if card1price = or < the_price_got%><font color="green"><%card1price%></font><%else%><font color="red"><%card1price%><%endif%>
Quote Reply
Re: [Westin] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
Nope that's not right either. Aaaaackkkk
Quote Reply
Re: [Westin] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
Email over GLinks admin details, and a page I can see this happening - and I'll have a quick look for ya.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Westin] Is there a way to compare numbers like if 0.85 > 0.65 then In reply to
Quote:
if card1price = or < the_price_got

....should be: >=

...if you are trying to do "greater than or equal to".