Select SUM

The following query returns the records I need.  But in addition to getting the records, I need to sum the total value of 'amount' based on the query.

I have tried the sum command, but can't get it to work.

Any ideas?
$query = sprintf("SELECT SUM amount FROM cbacks WHERE card_type = 'visa' AND mid = '$mid' AND receive_date >= '$date1' AND receive_date <= '$date2' AND amount >= '$amt1' AND amount <= '$amt2'");
 
$rs = mysql_query($query, $connect_crm) or die(mysql_error());
$row = mysql_fetch_assoc($rs);

Open in new window

fastfind1Asked:
Who is Participating?
 
Beverley PortlockConnect With a Mentor Commented:
Like so

$query = sprintf("SELECT SUM(amount) as totalAmount FROM cbacks WHERE card_type = 'visa' AND mid = '$mid' AND receive_date >= '$date1' AND receive_date <= '$date2' AND amount >= '$amt1' AND amount <= '$amt2'");
 
$rs = mysql_query($query, $connect_crm) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
echo $row['totalAmount'];
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.