RE: Re: [PHP] Addin a column of numbers not using MySQL

From: Date: Mon, 04 Aug 2003 21:04:29 +0000
Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
Groups: php.general 
Request: Send a blank email to php-general+get-158213@lists.php.net to get a copy of this message
Let me try and explain a little better and easier. What I am trying to do is take a list of values and add them to get. I am getting the values from a database query. Assuming that I had the following: val_1 100.00 val_2 150.00 val_3 200.00 val_4 250.00 val_5 100.00 What I want to do now is add up the values 1-5 and get 800.00. Does this help clarify? > > From: "Jay Blanchard" <jay.blanchard@niicommunications.com> > Date: 2003/08/04 Mon PM 04:57:17 EDT > To: "Ben C." <benc@cox.net>, <php-general@lists.php.net> > Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL > > [snip] > Unsure. How would I do that? > [/snip] > > Ben I think that we have a communications failure. Let's start > over...you wish to total a database column using php, correct? > Everything that you have been shown so far will do that. Is it possible > that there are no query results? If not, then we are doing the query > wrong. Try it with single quotes; > > $sql_2 = "SELECT paidamount FROM $tb_name WHERE id = '" . $id . "' > "; > > Please do a verbose check on the query to see if it is working properly > > if(!($result_2 = mysql_query($sql_2, $connection))){ > print("MySQL reports: " . mysql_error() . "\n"); > exit(); > } > > Let's use objects instead of arrays (humor me for a moment) > > while($row = mysql_fetch_object($result_2)){ > $paid = $row->paidamount; > echo "$paid \n"; > $total = $total + paid; > } > > echo "$total \n"; > > Please copy and paste the results into your reply >

« previous php.general (#158213) next »