-2

enter image description here how i can calculate the total sum between particular date (eg: 2016/06/16 to 2016 enter image description here/08/17). and which the date will be choose by the user from front end. I have tried something like this.

    $sql = "select sum(amount_no) from tsurphus where subDate BETWEEN '2016-03-01' AND '2016-08-05'";
    $q = mysql_query($sql);
    $row = mysql_fetch_array($q);
    echo 'Current Total Amount. Rs: ' . $row[0];

But here the problem is that to calculate the total amount i need to change the date from code. please help.. thank in advance.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Explorer
  • 13
  • 6

1 Answers1

1

In your query, you should group by the currency field.

Considering your field name is "currency", try this:

$sql = "SELECT SUM(amount_no), currency FROM tsurphus WHERE subDate BETWEEN '2016-03-01' AND '2016-08-05' GROUP BY currency";
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32