[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

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

0
fastfind1
Asked:
fastfind1
1 Solution
 
Beverley PortlockCommented:
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now