Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 8th, 2006, 04:34 PM
Registered User
Join Date: Nov 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding the values within an array

Hey all!

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

Function within a class file:

public static function getSomething($database){
    $query = "SELECT important FROM tblPurchases WHERE purchase = 3 AND buyer = 5";

    $result =  $database->Select($query);
    return $result;

PHP Web Page:

$function= pFunction::getSomething($_DATABASE);

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

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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add up values in an array? Lucy Classic ASP Basics 6 May 31st, 2005 05:26 AM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
Adding 2 values in a table Regornil JSP Basics 2 September 13th, 2004 02:32 AM
Adding Values NeilS21 Beginning VB 6 1 February 6th, 2004 10:45 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.