Example using "IF" "ELSE"
macm - December 24, 2006 - 15:41
| Project: | Computed Field |
| Version: | 4.7.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | macm |
| Status: | closed |
Jump to:
Description
Hi
I am not programmer and I think could be useful have a example using "IF" ""ELSE"
For example:
IF field_fruit = orange So field_fruit = 5
Ifelse field_fruit = apple So field_fruit = 7
If field_salad = tomato So field_salad = 6
Ifelse field_salad = potate So field_salad = 9
Result = field_fruit + field_salad
Cheers

#1
Yes, me too!
I was trying to create a quiz and wanted to calculate grades and display results. An example that would help me would be to test if question_1[0]['value'] = 'some_correct_value', then print 'correct', else print 'incorrect'.
#2
How about this:
<?phpif ($node->field_other_phone_type[0]['value']) {
$node_field[0]['value'] = $node->field_other_phone[0]['value'] .' ('. $node->field_other_phone_type[0]['value'] .')';
}
else {
$node_field[0]['value'] = $node->field_other_phone[0]['value'];
}
?>
I have several CCK fields that describe various phone numbers, including a generic one labeled 'Other'. I also have a text field labeled 'Other phone type', which is a text field describing what the 'Other' field is (cell. phone, pager, mother-in-law, etc.). I have a view created in which I display the phone number like this: "123-4567 (other cell. phone)". The other type field isn't always filled in, however, and I don't want the display to look like "123-4567 ()", so I check it before I set the computed field and either put the type in with parenthesis or not at all, depending on the value.
#3
Sorry for my silly comment, but where should I put this code? I´m trying to use this module for a couple of days now, and still trying to use it... unsuccessfully. (well, I must admit that as I´m not a programmer its a bit harder for me to get it...)
#4
Closing out old Drupal 4.7 issues, as it is no longer a supported release.