Jump to content

Adding the values within an array


Dave_Richards

Recommended Posts

Hey all!

was wondering if you could help me with my problem. I have the following code:

Function within a class file:

[code]public static function getSomething($database){
    $query = "SELECT important FROM tblPurchases WHERE purchase = 3 AND buyer = 5";
 
    $result =  $database->Select($query);
    return $result;
  }[/code]

PHP Web Page:

[code]$function= pFunction::getSomething($_DATABASE);

foreach($function as $result) {
$important = $result;

$count++;
}[/code]

This code counts the amount of records that match the SQL criteria and places the important variable into an array. However I would like to extract all values of "important" (which is an integer value) and add them together to produce a sum of all of the "important" values. Could somebody please advice me as to what I need to add to my code to acheive this.

Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.