I have a profile filed called Amount corresponding to each users, and I want to store multiple values in the profile field Amount. Bu using the custom module, the value of Amount is to be inserted on each registration (or it can be inserted any time by a cron program).

For example User Williams has Value 100 in his Amount field. This is not a single value, it may be

Time    Amount
Hour 1 :  10
Hour 2 :  30
Hour 3 :  20
Hour 4 :  35
Hour 5 :   5
Total  : 100

I want to display the total amount and individual amount by exact time.

How to do it?


You might be best installing content profile as this will allow you to use cck, when creating the profile field amount you can set it to unlimited which would allow you to store multiple values in an array for a single field.

The total would be another dynamic field which is calculated by adding the values from the amount array each time they are changed via a hook

To add the field to a content profile, follow the below steps:

  1. Edit the profile content type
  2. Go to manage fields
  3. Add a new "text field
  4. Fill in field details
  5. On this page you will see a "number of values" option, choose "unlimited"

You can update content profile fields as below, just put it in a custom module or something:

//load current user
global $user;
//find the users content profile
$uid = $user->uid;
$node = content_profile_load(profile,$uid);
$pid = $node->nid;
$node = node_load($pid);
//update the field AMOUNT
$node->field_AMOUNT[0]['value'] = $var1;
$node->field_AMOUNT[1]['value'] = $var2;
//do the same for the TOTAL with calculations
$node->field_TOTAL[0]['value'] = $var1 + $var2;
//save the content profile node
  • Thanks, I have installed the Content Profile module, and when I create the profile field Amount, I couldn't see the Unlimited option. Please explain your words which would allow you to store multiple values in an array for a single field in detail. – Ashok KS Jan 14 '12 at 6:29
  • Updated my answer – WestieUK Jan 16 '12 at 9:17
  • I think some error in your code, that's why I used this one, $node = new stdClass(); $node->type = 'profile'; $node->title = 'This is a title'; $node->body = 'This is the body.'; $node->teaser = 'This is the teaser.'; $node->uid = 25; $node->status = 0; $node->promote = 1; $var1 = 1753; $node->field_amount[0]['value'] = $var1; node_save($node); – Ashok KS Feb 13 '12 at 11:01

You need to create a new profile type in "drupal/module/profile.module" that is called "total."

  • But this field can store only one value, i want to store multiple values like the table above – Ashok KS Jan 13 '12 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.