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 <b>$contributorName</b><br>$total_amount<p>";
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 <b>$contributorName</b><br>$total_amount<p>";