Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying SUM results on web page

Status
Not open for further replies.

jtjones

IS-IT--Management
Nov 4, 2004
8
US
Hi newbie question,

I'm trying to run a query using the SUM command and display the results on a web page but the SUM results keep coming back as 0 when I try to use the SUM command. They're multiple donations from the same contributors.

I'm running MySQL 4.1.14 and PHP 5.0.4

Here's the code I've come up with:

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT idNumber, contributorName, SUM(amount) AS total_amount FROM ca_late_trans GROUP BY contributorName";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$contributorName=mysql_result($result,$i,"contributorName");
$total_amount=mysql_result($result,$i,"total_amount");
$idNumber=mysql_result($result,$i,"idNumber");


echo "$idNumber&nbsp;<b>$contributorName</b><br>$total_amount<p>";
 
Don't see why that wouldn't work.

On another (unrelated) point though, the idNumber value returned will be unpredictable unless its value is always the same for each contributor.
 
The idNumber is the same for each contributor. Thanks for the confirmation on the code though. I've run the query on my computer (Mac OS 10.3.9) and the web server with the same result (zeros for all contributors).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top