From this page, if what we need is SELECT single value, we can use fetchField
method like below:
$nbr_records = db_query("SELECT count(nid) FROM {joke}")->fetchField();
I've created single value Integer
field type with machine name field_subscription_period
attached to node type yearly_rent
.
I'm using this in Rules Action.
I've tested many db_query example with no luck.
Below is what I'm using, which it will get value of entity_id
2
:
$result = db_query("SELECT field_subscription_period_value FROM {field_data_field_subscription_period} WHERE entity_id = 2")->fetchField();
Above query will get value of entity_id
2
... but I want to SELECT field_subscription_period
value that related to the node. So, how to get value that related to the node?
-newly added-
I still don't understand how to use $node = node_load($nid);
. Lets say I want to use the value as variable to be calculated in date field.
I've tried below with no luck:
$node = node_load($nid);
$values = field_get_items('node', $node, 'field_subscription_period');
$newdate = strtotime("+$values year","$value");
return $newdate;
..and also I got error:
Notice: Undefined variable: nid in eval() (line 1 of /var/www/testd7/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7539 of /var/www/testd7/includes/common.inc).