• Hello,

    i have a site for smokers who have quit smoking. When a user registers he/she gets asked: When did quit? How many cigarettes did you smoke average/day? etc…

    I have buddypress installed and these fields are stored inside bp_xprofile_data.
    I managed to calculate statistics for each user on their profile page about how many cigarettes they have smoked and how much money they have used and saved…

    But how do i calculate the sum that each user has saved:
    user1=days not smoking * average cigarettes/day * price for one cigarette
    user2=days not smoking * average cigarettes/day * price for one cigarette
    ….
    And put that sum on the frontpage.

    I think i should somehow save the users “Saved euros” in user meta field but don’t now how.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jokke72

    (@jokke72)

    I think i got the idea.

    Check pastebin code, sorry i don’t now how to paste code here!

    And help me out here, my code dosn’t work (no suprise?), so how do i fix it?
    I know i’m on the right track.

    Thread Starter jokke72

    (@jokke72)

    Really nobody, any ideas? Now im dissapointed!

    Check out wp_user_query($args)

    The pastebin does not show what the $savings and $saasto; contain?

    Return all the user id’s and data then use your foreach loop to make the sum.

    $dollars++ = get_user_meta($user->ID, 'user_savings', true);

    Is it euro’s or dollars, what is the price difference between different areas, just the number might be better?

    HTH

    David

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calculate sum of users custom feild’ is closed to new replies.