Forum Moderators: phranque

Message Too Old, No Replies

XSSI Conditional Expressions and Test Conditions

if exper

         

matc

12:34 pm on May 27, 2004 (gmt 0)

10+ Year Member



Hello all,

I am trying to develop a snippet of code that tests if an existing value given is greater or less than a certain numbered scale of values.

This is the code I have so far. I'm not that keen to state every value separately because the page gets quite high traffic and will probably make the server slow.

Can any one off any advice to getting these equations to work reliably.

Any value from 0 to down to -60
<!--#if expr="(${w5d.day1.min}<= 0) && (${w5d.day1.min}>= -60)" -->
<!--#set var="mincolbg1" value="#99ccff" -->
<!--#endif -->

Any value from 1 up to 24
<!--#if expr="(${w5d.day1.min}>= 1) && (${w5d.day1.min}<= 24)" -->
<!--#set var="mincolbg1" value="#ffff98" -->
<!--#endif -->

Any value from 25 up to 60
<!--#if expr="(${w5d.day1.min}>= 25) && (${w5d.day1.min}<= 60)" -->
<!--#set var="mincolbg1" value="#ff9641" -->
<!--#endif -->

Many thanks for any help offered with this

mat

gergoe

1:08 pm on May 27, 2004 (gmt 0)

10+ Year Member



As far as I know, you can't compare numbers like this, since everything is treated as string, and the comparison is done on strings, not on numbers. Comparing 6 and 10 for example will give you a strange result (6 is greater than 10). You'll need to use regular expressions for this purpose, which is a bit complicated, but I don't thing that there's any other way.

For example your first condition turned into a regex will look like this:


<!--#if expr="${w5d.day1.min} = /^(0¦-([1-9]¦[0-5][0-9]¦60))$/" -->

Don't forget to change the broken pipe characters to normal pipes.

See the the mod_include documentation [httpd.apache.org] and search the web for details on the Regular Expressions.

matc

5:03 pm on May 27, 2004 (gmt 0)

10+ Year Member



Hi gergoe,

Thanks for the speedy reply!

I used your pointers/URL and got to the following result. It covers all the agreed values and makes the site look a lot better!

Thank you very much for your help mate.

<!--#if expr="${w5d.day1.min} = /^[1-9]¦1[0-9]¦2[0-4]$/" -->
<!--#set var="mincolbg" value="vartemp124" -->
<!--#elif expr="${w5d.day1.min} = /^2[5-9]¦[3-6][0-9]$/" -->
<!--#set var="mincolbg" value="vartemp2560" -->
<!--#endif -->
<!--#if expr="${w5d.day1.min} = /^-/" -->
<!--#set var="mincolbg" value="vartemp060" -->
<!--#endif -->

<!--#if expr="${w5d.day1.max} = /^[1-9]¦1[0-9]¦2[0-4]$/" -->
<!--#set var="maxcolbg" value="vartemp124" -->
<!--#elif expr="${w5d.day1.max} = /^2[5-9]¦[3-6][0-9]$/" -->
<!--#set var="maxcolbg" value="vartemp2560" -->
<!--#endif -->
<!--#if expr="${w5d.day1.max} = /^-/" -->
<!--#set var="maxcolbg" value="vartemp060" -->
<!--#endif -->

:)mat