Im trying to create a report that prints each account number, every transaction for that account, print the sub total for each account, then a grand total.
The code I have used so far is as follows:
$sql = "SELECT tbl_visa.account_number,
tbl_accounts.account_name,
tbl_visa.total,
tbl_employee_visa.employee_name
FROM tbl_visa, tbl_accounts, tbl_employee_visa
WHERE tbl_visa.account_number = tbl_accounts.account_number
AND tbl_visa.id = tbl_employee_visa.id
ORDER BY(tbl_visa.account_number) ASC";
$result = mysql_query($sql,$cn) or die($sql.mysql_error());
$result2 = mysql_query("SELECT tbl_visa.account_number,
SUM(tbl_visa.total)
FROM tbl_visa
GROUP BY(tbl_visa.account_number)
ORDER BY(tbl_visa.account_number) ASC",$cn)
or die($result2.mysql_error());
$numresults = mysql_num_rows($result);
$numresults2 = mysql_num_rows($result2);
the first select statement gathers all transactions for every account, the 2nd select statement sums the totals for every account, but what I need to do now is after each account print the subtotal for that account, also would like to be able to print a total if a user has more than one transaction in a account
Any help would be greatly appreciated
I'm fairly new to PHP so if I'm going about this the wrong way or doing something that doesn't make sense please let me know
Thanks