Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By uw07 on
How would I go about updating a Computed Field with every view?
I currently have a CCK content type ('user profile') that has Computed Fields. For example, I have a "First Name" field with the following code:
global $user
$node_field[0]['value'] = $user->$profile_firstname;
This works great. However, if the user changes the profile_firstname field in their profile, this field is not updated in the custom content type (unless I enter and do an edit/resave). Is there anyway to have this field updated automatically?
Comments
I tried the following
I tried the following code:
But received: user warning: Table 'drupal.userprofile' doesn't exist query: SELECT nid FROM userprofile in /wwwroot/includes/database.mysql.inc on line 172.
I tried replacing 'userprofile' with 'book' and this worked. I don't understand because 'userprofile' is the name of my content type I created, but it can't find the table??
Anyone?
Anyone?
...
You can store the UID in the field. This number doesn't change. Then, in the "display code", type the code to print this user's profile name.
That is an excellent idea! I
I think I have this working. The downside is that the computed field doesn't actually store anything of value.
Ideally, the computed fields I have would be updated automatically through some sort of script (like the one above, which I still don't understand why it's not working...)
Access user profile field based on id
Ok, if I have the user's ID, then how do I go about accessing a field in their profile based on their id?
I have for the field value:
How would I display the user's name?
For example... I want to be
For example...
I want to be able to go into the user's 'user profile' custom content types and submit, so as to compute and populate the fields. However, when I do this, it's using my userid. How can I use the id for the profile I'm editing?