Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:create:filter-boolean [10.12.2014 15:05] – [Linking Multiple Conditions] alexander.ritteren:create:filter-boolean [23.10.2026 14:44] (current) – external edit 127.0.0.1
Line 3: Line 3:
 It may be necessary to link multiple conditions for a filter ([[filters|Filters and Conditional Questions]]). Some examples of these links: It may be necessary to link multiple conditions for a filter ([[filters|Filters and Conditional Questions]]). Some examples of these links:
  
-  * Did the respondent select the option "fairly unimportant" (2) **or** "fairly important" (3), but not "completely unimportant (1) or "particularly important" (4)?+  * Did the respondent select the option "fairly unimportant" (2) **or** "fairly important" (3), but not "completely unimportant" (1) or "particularly important" (4)?
   * Did the respondent state that he owned a car **and** it has a gas engine?   * Did the respondent state that he owned a car **and** it has a gas engine?
   * Does the respondent **neither** watch the news on TV **nor** read it in the paper?   * Does the respondent **neither** watch the news on TV **nor** read it in the paper?
Line 17: Line 17:
  
 <code php> <code php>
-(value('AB01') == 1 or 2)  // does not return an error as such, but also does not return the desired result +(value('AB01') == 1 || 2)  // does not return an error as such, but also does not return the desired result 
-(value('AB01') == 1) or (value('AB01') == 2)  // correct linking of two conditions+(value('AB01') == 1) || (value('AB01') == 2)  // correct linking of two conditions
 </code> </code>
  
Line 33: Line 33:
   * ''value('TF02_03') == 2'' (owns a cell phone)   * ''value('TF02_03') == 2'' (owns a cell phone)
  
-An ''and'' is put in between both conditions. The conditions can be put in brackets so that it stays clear:+An ''&&'' (and) is put in between both conditions. The conditions can be put in brackets so that it stays clear:
  
 <code php> <code php>
-(value('TF02_01') == 2) and (value('TF02_03') == 2)+(value('TF02_01') == 2) && (value('TF02_03') == 2)
 </code> </code>
  
-In this example, the inner brackets would not be essential because the ''%%==%%'' before the ''and'' is executed (similar to performing an order of operation calculation). However, using brackets plays it safe when there are complicated constructions.+In this example, the inner brackets would not be essential because the ''%%==%%'' is executed before the ''&&'' (similar to performing an order of operation calculation). However, using brackets plays it safe when there are complicated constructions.
  
 In IF filters, the whole condition is put in round brackets again (because the condition is always put in brackets when using the IF function). A filter with the linked condition therefore looks as follows: In IF filters, the whole condition is put in round brackets again (because the condition is always put in brackets when using the IF function). A filter with the linked condition therefore looks as follows:
- 
  
 <code php> <code php>
-if ((value('TF02_01') == 2) and (value('TF02_03') == 2)) {+if ((value('TF02_01') == 2) && (value('TF02_03') == 2)) {
   question('IN20');  // data transfer cell phone-computer   question('IN20');  // data transfer cell phone-computer
 } }
Line 54: Line 53:
 <code php> <code php>
 if ( if (
-  (value('TF02_01') == 2) and+  (value('TF02_01') == 2) &&
   (value('TF02_03') == 2)   (value('TF02_03') == 2)
 ) { ) {
Line 65: Line 64:
 ===== The One OR the Other Condition is True ===== ===== The One OR the Other Condition is True =====
  
-The following example shows a check as to whether at least one of the first three items from the question displayed above was chosen (owns a computer, DSL connection or cell phone). The "or" operator is used here in order to do so. In the event that none of the sub-conditions are true, the questionnaire will jump to the end. +The following example shows a check as to whether at least one of the first three items from the question displayed above was chosen (owns a computer, DSL connection or cell phone). For this, the operator ''||'' is used, the logical OR. In the event that none of the sub-conditions are true, the questionnaire will jump to the end. 
  
 <code php> <code php>
 if ( if (
-  (value('TF02_01') == 2) or +  (value('TF02_01') == 2) || 
-  (value('TF02_02') == 2) or+  (value('TF02_02') == 2) ||
   (value('TF02_03') == 2)   (value('TF02_03') == 2)
 ) { ) {
   // display a text on the screen   // display a text on the screen
-  html('<p>Select at least one of the three options!</p>');+  html('<p>At least one of the three options was selected!</p>');
 } else { } else {
   // none selected: end survey   // none selected: end survey
Line 91: Line 90:
  
 <code php> <code php>
-if ((value('AB01') > 0) and (value('AB01') < 4)) {+if ((value('AB01') > 0) && (value('AB01') < 4)) {
   question('BB02');   question('BB02');
 } }
Line 101: Line 100:
 <code php> <code php>
 if ( if (
-  (value('AB01') == 1) or +  (value('AB01') == 1) || 
-  (value('AB01') == 2) or+  (value('AB01') == 2) ||
   (value('AB01') == 3)   (value('AB01') == 3)
 ) { ) {
Line 113: Line 112:
 <code php> <code php>
 $a1 = value('AB01'); $a1 = value('AB01');
-if (($a1 == 1) or ($a1 == 2) or ($a1 == 3)) {+if (($a1 == 1) || ($a1 == 2) || ($a1 == 3)) {
   question('BB02');   question('BB02');
 } }
Line 158: Line 157:
 <code php> <code php>
 if (!( if (!(
-  (value('AB01') == 1) or +  (value('AB01') == 1) || 
-  (value('AB01') == 2) or+  (value('AB01') == 2) ||
   (value('AB01') == 3)   (value('AB01') == 3)
 )) { )) {
Line 166: Line 165:
 </code> </code>
  
-The only difference between this and the OR example above is the exclamation point, which is equivalent to ''not'', and the additional brackets at the beginning and the end.+The only difference between this and the OR example above is the exclamation point (''!''), which is equivalent to ''not'', and the additional brackets at the beginning and the end.
  
 In addition, there is a mathematical distributive law when calculating with the NOT operator. The following filter has the same effect as the previous one: In addition, there is a mathematical distributive law when calculating with the NOT operator. The following filter has the same effect as the previous one:
Line 173: Line 172:
 <code php> <code php>
 if ( if (
-  (value('AB01') != 1) and +  (value('AB01') != 1) && 
-  (value('AB01') != 2) and+  (value('AB01') != 2) &&
   (value('AB01') != 3)   (value('AB01') != 3)
 ) { ) {
Line 185: Line 184:
 <code php> <code php>
 if ( if (
-  (value('AB01') == 1) or +  (value('AB01') == 1) || 
-  (value('AB01') == 2) or+  (value('AB01') == 2) ||
   (value('AB01') == 3)   (value('AB01') == 3)
 ) { ) {
Line 192: Line 191:
 } else { } else {
   goToPage('end');   goToPage('end');
 +}
 +</code>
 +
 +===== Nested filters =====
 +
 +Sometimes it makes sense to set a filter in another filter. Let's take the situation where, depending on the answer to FF01, either question FF02 or FF03 was displayed. And now, depending on these two questions, another filter should follow. The individual filters would be simple:
 +
 +<code php>
 +if (value('FF02') == 1) {
 +  replace('%stimulus%', 'Dog');
 +} else {
 +  replace('%stimulus%', 'Cat');
 +}
 +</code>
 +
 +<code php>
 +if (value('FF03') == 1) {
 +  replace('%stimulus%', 'Wolf');
 +} else {
 +  replace('%stimulus%', 'Tiger');
 +}
 +</code>
 +
 +But now only one of these two filters should become active ... depending on which value FF01 had. To do this, these filters are placed "inside" another filter.
 +
 +<code php>
 +if (value('FF01') == 1) {
 +  // Filter für FF02
 +  if (value('FF02') == 1) {
 +    replace('%stimulus%', 'Dog');
 +  } else {
 +    replace('%stimulus%', 'Cat');
 +  }
 +} else {
 +  // Filter für FF03
 +  if (value('FF03') == 1) {
 +    replace('%stimulus%', 'Wolf');
 +  } else {
 +    replace('%stimulus%', 'Tiger');
 +  }
 } }
 </code> </code>
en/create/filter-boolean.1418220338.txt.gz · Last modified: by alexander.ritter
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki