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
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

nisguy - March 13, 2007 - 19:28

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

oadaeh - September 11, 2007 - 22:48

How about this:

<?php
 
if ($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

Rosamunda - May 6, 2008 - 14:58

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

Moonshine - September 1, 2008 - 18:15
Status:active» closed

Closing out old Drupal 4.7 issues, as it is no longer a supported release.

 
 

Drupal is a registered trademark of Dries Buytaert.