[PHP-DB] Re: Adding totals

2002-05-21 Thread César L . Aracena

It works...

Thanks a lot.
  - Original Message - 
  From: Adam Royle 
  To: [EMAIL PROTECTED] ; [EMAIL PROTECTED] 
  Sent: Tuesday, May 21, 2002 2:11 AM
  Subject: Re: Adding totals


  This should be it (if I am understanding you correctly).

  Adam

  $strSQL = SELECT SUM(columnName) as sum FROM tblName;
  $result = mysql_query($strSQL);

  while ($row = mysql_fetch_array($result)){
  $total = $row[sum];
  }

  
  Hi all,

  Is there a way for me in PHP4 to add all the contens (floating numbers) =
  of a cartain column whithin a row and show up the result? I have several =
  time inputs and need to show the total.

  Thanx.

  Cesar Aracena
  [EMAIL PROTECTED]
  Neuquen, Argentina



[PHP-DB] Re: Adding totals

2002-05-21 Thread Frank Flynn

I'm sure you could add up the results as you fetch them and only display the
total.  But even easier why not ask the  DB to return the sum?

SELECT sum(my_col)
  FROM my_table
   WHERE whatever

This will only return one row with the total (note you can only select
columns that are using an aggregate for this to work) See also GROUP BY

Good luck,
Frank

 
 From: César L. Aracena [EMAIL PROTECTED]
 Date: Tue, 21 May 2002 01:49:28 -0300
 To: PHP DB List [EMAIL PROTECTED]
 Subject: Adding totals
 
 Hi all,
 
 Is there a way for me in PHP4 to add all the contens (floating numbers) of a
 cartain column whithin a row and show up the result? I have several time
 inputs and need to show the total.
 
 Thanx.
 
 Cesar Aracena
 [EMAIL PROTECTED]
 Neuquen, Argentina


-- 
Frank Flynn
Poet, Artist  Mystic



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




[PHP-DB] Re: Adding totals

2002-05-20 Thread Adam Royle

This should be it (if I am understanding you correctly).

Adam

$strSQL = SELECT SUM(columnName) as sum FROM tblName;
$result = mysql_query($strSQL);

while ($row = mysql_fetch_array($result)){
$total = $row[sum];
}


Hi all,

Is there a way for me in PHP4 to add all the contens (floating numbers) =
of a cartain column whithin a row and show up the result? I have several =
time inputs and need to show the total.

Thanx.

Cesar Aracena
[EMAIL PROTECTED]
Neuquen, Argentina