[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Comparing numeric value using IF
****** message to minivend-users from Ed LaFrance <edl@newmediaems.com> ******
As others on this list have pointed out, you should be mindful of the type
of data which you are working with (form field value, database field value,
scratch variable) and verify that it actually contains the data you expect.
You must also use the correct type of IF for the data type.
Finally, bear in mind that 0 is a logical false and 1 is a logical true, so
in your case you can write IF's without the comparison, for example...
for a form field value or logged-in userdb value:
[if value myfield]
value is 1
[else]
value is 0
[/else]
[/if]
for a database field in a results list or flypage:
[if-item-data myfile myfield]
value is 1
[/if-item-data]
for a database field in a loop construct:
[if-loop-data myfile myfield]
value is 1
[else]
value is 0
[/else]
[/if-loop-data]
for a scratch variable:
[if scratch myfield]
value is 1
[else]
value is 0
[/else]
[/if]
using explicit:
[if explicit]
[condition]
$a = '[tag_to_return_value_of_myfield]';
return $a;
[/condition]
value is 1
[else]
value is 0
[/else]
[/if]
- Ed L.
At 06:47 PM 7/2/00 -0500, you wrote:
>****** message to minivend-users from "Curt Hauge"
><chc@mninter.net> ******
>
>Hi List,
>
>On MV 4.04, Linux Mandrake 6.0, I have been trying to do what seems to be a
>simple comparison of numeric values. I have researched the docs and several
>perl sites, but still can't get the desired result. Basically, I wish to
>check the value of My_field to see if it is equal to 1 (It is either 1 or
>0). Here is a sample of what I have tried:
>
>[if type="value" term="My_field" op="==" compare="1"]
>Hello
>[/if]
>(tried op="eq", op="=~", term="[item-data My_file My_field]", compare="/1/",
>compare="^1", compare="/^1/", and several variations of these)
>
>also:
>
>[if value My_field == /^1/]
>Hello
>[/if]
>
>which always produces Hello, whether value is a 1 or 0
>
>(tried =~, [My_field], [item-data My_file My_field], == 1, == ^1, and
>variants)
>
>and:
>[if explicit]
> [condition]
> $My_value = '[value My_field]';
> return 1 if $My_value =~ /1/;
> return 0;
> [/condition]
>Hello
>[/if]
>
>(tried [value [item-data My-file My_field]], [value [My_field]], ==, and
>variants)
>
>A sampling of error log, in no particular order:
>
>Bad if 'value My_field == ^1': syntax error at (eval 323) line 1, near "==
>^"
>Bad if 'value My_field =~ ^1': syntax error at (eval 354) line 1, near "=~
>^"
>Bad if 'value 0 = 1': Can't modify constant item in scalar assignment at
>(eval 357) line 2, at EOF
>Bad if 'value My_field = 1': Can't modify constant item in scalar assignment
>at (eval 349) line 2, at EOF
>Bad if 'value 0 g [My_field]': syntax error at (eval 303) line 1, near "q{}
>g "
>Bad if 'value My_field = 1': Can't modify constant item in scalar assignment
>at (eval 351) line 2, at EOF
>
>It has been several hours of trial and error and, while I do have a
>workaround (which is not based on a conditional expression), I really wish
>to do it this way. All help is greatly appreciated.
>
>Thanks in advance,
>
>Curt
>
>
>-
>To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
>email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
>Archive of past messages: http://www.minivend.com/minivend/minivend-list
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| New Media E.M.S. Software Solutions for Business |
| 12831 Blanco Ct. Consulting |
| Poway, CA 92064 U.S.A. Custom Programming |
| 858-486-6508 Internet and eCommerce |
| 630-604-4265 eFax |
| edl@newmediaems.com |
| http://www.newmediaems.com |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list