PHP2005 Posted September 10, 2007 Share Posted September 10, 2007 How do I write a calculation? I am new on write calculation. I have a database where I keep record of the registration and workshop, The registration fields are F1, F2, and F3 and the workshop fields are W1, W2, W3, and W4 How do I write a calculation If I am register to any of (F1, F2, or F3) and NONE of the W1, W2, W3, or W4 I would check the radio button as “Registration Only” If I a register to any of (F1, F2, or F3) and any of W1, W2, W3, or W4 I would check the radio button as “Registration and workshop If I am not register and only attend any of the workshop I would check the radio button as “Workshop Only” Any help will be appreciated! Link to comment Share on other sites More sharing options...
dreamingmind Posted September 11, 2007 Share Posted September 11, 2007 php2005, Well there are a lot of ways to do this. How 'bout a Let statement because it will allow us to break this into smaller chunks and make it a little easier to understand. Let ( [ reg = case( (F1 & F2 & F3) = "" ; 0 ; 1 ); wks = case( (W1 & W2 & W3 & W4) = "" ; 0 ; 2 ) ] ; choose( reg + wks ; "None"; "Registration Only";"Workshop Only";"Registration and Workshop") ) In a nutshell, I concatenate the two sets of fields and check to see if they have any value. Based on the result, I set a variable to a number so can later add the variables and come up with a unique sum for each possible which I can then use to pick the text I want using a choose function. Regards, Don Link to comment Share on other sites More sharing options...
PHP2005 Posted September 11, 2007 Author Share Posted September 11, 2007 Hi Don, Thank you for your help. I have the following calculation: Case ( not IsEmpty (Registration) and IsEmpty ( Workshop ); "Conference Only")& Case ( not IsEmpty (Registration) and not IsEmpty (Workshop); "Conference and Workshop")& Case ( IsEmpty (Registration) and not IsEmpty (Workshop); "Workshop Only")& And my problem now is how do I add a case statement if in case the value of Registration be equal to “Pre-Conference” and not IsEmpty(Workshop); “Pre-Conference Only”) it will show up Pre-Conference only at the field. Thank you. Link to comment Share on other sites More sharing options...
Anuviel Posted September 14, 2007 Share Posted September 14, 2007 I think that Case evaluates until it encounters the first condition only so "and" statement does not make much sense in it - I learned that here on the forums so an If statement would be much better in this case OR I got it wrong. I might be wrong, get a second opinion before taking any of my advice. If ( not IsEmpty (Registration) and IsEmpty ( Workshop ); "Conference Only" ; "") Link to comment Share on other sites More sharing options...
Genx Posted September 15, 2007 Share Posted September 15, 2007 (edited) Anuviel - you're right in terms of the case only evaluating until it matches a condition but maybe not in the way you think: Case( Condition1 ; Result1 ; Condition2 ; Result2 ; ConditionN ; ResultN ; Default If No Conditions Met ) If condition1 is met, then the case function short circuits and throws out Result1 - Condtions2 to n aren't checked because Condition1 evaluated to true. Conditions can be anything however - the primary thing that is evaluated is whether the expression produces a true or false result: IsEmpty("") and IsEmpty("") would for example produce true and so Result1 would be thrown out. The If statement can really be replaced by a single case statement if you really wanted, though it may become less clear: Case( condition ; true ; false ) If( condition ; true ; false ) PHP 2005 - A case statement evaluates multiple conditions, not one set at a time, so you're statement could be written as: Case ( IsEmpty (Registration & Workshop); "" ; IsEmpty ( Workshop ) ; "Conference Only"; IsEmpty (Registration); "Workshop Only"; "Conference and Workshop") Don - the function's great, but don't use = "" to try and work out if a string is empty: Let ( [ reg = case( IsEmpty(F1 & F2 & F3) ; 0 ; 1 ); wks = case( IsEmpty(W1 & W2 & W3 & W4) ; 0 ; 2 ) ] ; choose( reg + wks ; "None"; "Registration Only";"Workshop Only";"Registration and Workshop") ) End random reply : Edited September 15, 2007 by Guest Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 6210 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now