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

2003-08-14 Thread Jason Wong
On Tuesday 05 August 2003 04:01, Ben C. wrote:

 It still returns '0'.  I think we are missing something.  Any other ideas? 
 Anyone else have any ideas?

My ideas are:

1) turn on FULL error reporting
2) print out all your variables at every step

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
America!!  I saw it all!!  Vomiting!  Waving!  JERRY FALWELLING into
your void tube of UHF oblivion!!  SAFEWAY of the mind ...
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Justin French
Do you mean something like:

?
$i = 0;
$sql = SELECT a,b,c FROM foo;
$res = mysql_query($sql);
while($myrow = mysql_fetch_array($res))
{
$i++;
echo $i.br /;
echo $myrow['a'] .br /;
echo $myrow['b'] .br /;
echo $myrow['c'] .br /;
}
?
Justin

On Monday, August 4, 2003, at 05:34  PM, Ben C. wrote:

How do I add a column of numbers generated through a MySQL query 
without
using the SQL SUM() function? I have tried looking through the 
different
documentation.  I am probably missing something.

Thanks,

Ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
---
[This E-mail scanned for viruses]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

2003-08-04 Thread Ben C.
Yes.  From there I want to add all the 'a' values together using PHP.

-Original Message-
From: Justin French [mailto:[EMAIL PROTECTED]
Sent: Monday, August 04, 2003 12:40 AM
To: Ben C.
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Addin a column of numbers not using MySQL


Do you mean something like:

?
$i = 0;
$sql = SELECT a,b,c FROM foo;
$res = mysql_query($sql);
while($myrow = mysql_fetch_array($res))
{
$i++;
echo $i.br /;
echo $myrow['a'] .br /;
echo $myrow['b'] .br /;
echo $myrow['c'] .br /;
}
?

Justin

On Monday, August 4, 2003, at 05:34  PM, Ben C. wrote:

 How do I add a column of numbers generated through a MySQL query 
 without
 using the SQL SUM() function? I have tried looking through the 
 different
 documentation.  I am probably missing something.

 Thanks,

 Ben


 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 ---
 [This E-mail scanned for viruses]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jason Wong
On Monday 04 August 2003 15:59, Ben C. wrote:
 Yes.  From there I want to add all the 'a' values together using PHP.

So do it then. 

$total = $total + $myrow['a'] // or something as you go through the loop
  // is just one of the ways to do this


-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
A beautiful woman is a picture which drives all beholders nobly mad.
-- Emerson
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
I tried the code you provided below but it returned 0.  Is there another way I can do 
it? 


 
 From: Jason Wong [EMAIL PROTECTED]
 Date: 2003/08/04 Mon AM 04:25:13 EDT
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Addin a column of numbers not using MySQL
 
 On Monday 04 August 2003 15:59, Ben C. wrote:
  Yes.  From there I want to add all the 'a' values together using PHP.
 
 So do it then. 
 
 $total = $total + $myrow['a'] // or something as you go through the loop
   // is just one of the ways to do this
 
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 A beautiful woman is a picture which drives all beholders nobly mad.
   -- Emerson
 */
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
I tried doing as you said and it returned 0.  Is there another way to add up the 
column?

 
 From: Jason Wong [EMAIL PROTECTED]
 Date: 2003/08/04 Mon AM 04:25:13 EDT
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Addin a column of numbers not using MySQL
 
 On Monday 04 August 2003 15:59, Ben C. wrote:
  Yes.  From there I want to add all the 'a' values together using PHP.
 
 So do it then. 
 
 $total = $total + $myrow['a'] // or something as you go through the loop
   // is just one of the ways to do this
 
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 A beautiful woman is a picture which drives all beholders nobly mad.
   -- Emerson
 */
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jason Wong
On Tuesday 05 August 2003 01:21, Ben C. wrote:
 I tried the code you provided below but it returned 0.  Is there another
 way I can do it?

Please post your code.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Trust me.  I know what I'm doing.
-- Sledge Hammer
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
I tried doing as you said and it returned 0.  Is there another way to
add up the column?
[/snip]

$sql = SELECT foo FROM table WHERE you have conditions ;
if(!($result = mysql_query($sql, $connection))){
   print(MySQL reports:  . mysql_error() . \n);
   exit();
}

while($row = mysql_fetch_object($result)){
   $total = $total + $row-foo; //each time through add the new amount
to the last amount
}
echo$total\n;

HTH!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
CODE Begin-
$sql_2 = SELECT SUM(paidamount) as paid
FROM $tb_name
WHERE id = \$id\
;

$result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result_2)) {
$paid = $row['paid'];
}
CODE End-

What I want to do from here is add up all the 'paid' figures.

 
 From: Jason Wong [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 01:55:40 EDT
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Addin a column of numbers not using MySQL
 
 On Tuesday 05 August 2003 01:21, Ben C. wrote:
  I tried the code you provided below but it returned 0.  Is there another
  way I can do it?
 
 Please post your code.
 
 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 Trust me.  I know what I'm doing.
 -- Sledge Hammer
 */
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
while ($row = mysql_fetch_array($result_2)) {
$paid = $row['paid'];
}
CODE End-

What I want to do from here is add up all the 'paid' figures.
[/snip]

while ($row = mysql_fetch_array($result_2)) {
$paid = $row['paid'];
$total = $total + $paid;
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
$sql_2 = SELECT SUM(paidamount) as paid
FROM $tb_name
WHERE id = \$id\
;
[/snip]

Ben I would also check the query with

echo$sql_2 \n;

You may be surprised that what you get back is not what you intended. 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
It still returns '0'.  I think we are missing something.  Any other
ideas?  Anyone else have any ideas?
[/snip]

echo the SELECT statement to make sure that $id is worth something

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
CODE Begin-
$sql_2 = SELECT SUM(paidamount) as paid
FROM $tb_name
WHERE id = \$id\
;

$result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result_2)) {
$paid = $row['paid'];
}
CODE End-
[/snip]

FOUND IT!

CODE Begin-
$sql_2 = SELECT paidamount
FROM $tb_name
WHERE id = \$id\
;

$result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result_2)) {
$paid = $row['paidamount'];
  $total = $total + $paid;
}
CODE End-


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
I tried the code again and still returns a '0'.  It looks like the
while() is only looping one record at a time.  It does looks like it is
add all the records.  Do you or anyone have any other suggestions?  
[/snip]

D'oh! *slaps forehead*! It IS getting only one record! Dang! SELECT
SUM(foo) will only return the sum of the column foo...one record! Repost
your query and I can help

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
When I echo the select state the id is the first of many ids that need
to be added together.  It is still not summing the total value of the
records.
[/snip]

Are you looping through the id's somehow?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[snip]
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?
[/snip]

Good, we're on the right path. Please try the code I sent previously

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jay Blanchard
[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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
When I echo the select state the id is the first of many ids that need to be added 
together.  It is still not summing the total value of the records.

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:09:36 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 It still returns '0'.  I think we are missing something.  Any other
 ideas?  Anyone else have any ideas?
 [/snip]
 
 echo the SELECT statement to make sure that $id is worth something
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
I tried the code again and still returns a '0'.  It looks like the while() is only 
looping one record at a time.  It does looks like it is add all the records.  Do you 
or anyone have any other suggestions?  

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 02:16:22 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 while ($row = mysql_fetch_array($result_2)) {
   $paid = $row['paid'];
 }
 CODE End-
 
 What I want to do from here is add up all the 'paid' figures.
 [/snip]
 
 while ($row = mysql_fetch_array($result_2)) {
   $paid = $row['paid'];
   $total = $total + $paid;
 }
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
Unsure.  How would I do that?

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:36:15 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 When I echo the select state the id is the first of many ids that need
 to be added together.  It is still not summing the total value of the
 records.
 [/snip]
 
 Are you looping through the id's somehow?
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
When I echo the select state the id is the first of many ids that need to be added 
together.  It is still not summing the total value of the records.

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:09:36 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 It still returns '0'.  I think we are missing something.  Any other
 ideas?  Anyone else have any ideas?
 [/snip]
 
 echo the SELECT statement to make sure that $id is worth something
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
When I echo the select state the id is the first of many ids that need to be added 
together.  It is still not summing the total value of the records.

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:09:36 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 It still returns '0'.  I think we are missing something.  Any other
 ideas?  Anyone else have any ideas?
 [/snip]
 
 echo the SELECT statement to make sure that $id is worth something
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
Jay, 

It still returns '0'.  I think we are missing something.  Any other ideas?  Anyone 
else have any ideas?

Ben

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 03:10:15 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL
 
 [snip]
 CODE Begin-
 $sql_2 = SELECT SUM(paidamount) as paid
   FROM $tb_name
   WHERE id = \$id\
   ;
 
 $result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());
 
 while ($row = mysql_fetch_array($result_2)) {
   $paid = $row['paid'];
 }
 CODE End-
 [/snip]
 
 FOUND IT!
 
 CODE Begin-
 $sql_2 = SELECT paidamount
   FROM $tb_name
   WHERE id = \$id\
   ;
 
 $result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());
 
 while ($row = mysql_fetch_array($result_2)) {
   $paid = $row['paidamount'];
   $total = $total + $paid;
 }
 CODE End-
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
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 [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:57:17 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 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
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Ben C .
Jay, No results are returned.  It is blank.

 
 From: Jay Blanchard [EMAIL PROTECTED]
 Date: 2003/08/04 Mon PM 04:57:17 EDT
 To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
 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
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Jim Lucas
Give an example db layout and/or array layout that you plan on using.

Would I be correct in assuming that the array would look something like
this?

$values['val_1'] = 100.00;
$values['val_2'] = 150.00;
$values['val_3'] = 200.00;
$values['val_4'] = 250.00;
$values['val_5'] = 100.00;

if this is correct you could do something like this.

$t=0;
foreach($values AS $amnt)
  $t += $amnt;

echo $t;  // this should return 800

if you wanted the formatted return to be something like xxx.xx you'll want
to use something like number_format()

if for some reason you are getting it from mysql then it could look like the
following.

$sql = SELECT title, val FROM tbl;
$results = mysql_query($sql);

$t=0;
while($row = mysql_fetch_assoc($results)) {
  $t += $row['val'];
}
echo $t;

Maybe you have a different style sql statement.

$sql = SELECT SUM(val) FROM tbl;
$results = mysql_query($sql);
list($t) = mysql_fetch_row($results)) {
echo $t;

Notice the difference in mysql_fetch_* functions

if you want the second sql statement used but want to refer to it by a name.
do this

$sql = SELECT SUM(val) AS total FROM tbl;
$results = mysql_query($sql);
$arr = mysql_fetch_assoc($results);
echo $arr['total'];


If i confused you with all the different ways to do this, don't worry, I
confused myself also.

If need be, I will explain more.

Jim Lucas

- Original Message -
From: Ben C. [EMAIL PROTECTED]
To: Jay Blanchard [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Monday, August 04, 2003 2:04 PM
Subject: RE: Re: [PHP] Addin a column of numbers not using MySQL


 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 [EMAIL PROTECTED]
  Date: 2003/08/04 Mon PM 04:57:17 EDT
  To: Ben C. [EMAIL PROTECTED],  [EMAIL PROTECTED]
  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
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-08-04 Thread Curt Zirzow
* Thus wrote Ben C. ([EMAIL PROTECTED]):
 I tried doing as you said and it returned 0.  Is there another way to add up the 
 column?

Please restart this discussion in a new thread, I have no clue what
you are trying to do anymore.

Give an brief example of your query and your php code and what you
want to accomplish.


Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php