Hey guys im here again with another question on how to solve this specific problem i have, Whic is also releated on my last thread which is http://www.daniweb.com/web-development/php/threads/461702/cant-combine-two-sql-statement .. so the question now is

i have this table

 Name        Payment_type        Service_charge

 test 1        Cash                 10
 test 2        Cash                 20
 test 3        Charge               100
 test 4        Charge               100
 test 5        Invoice               50

output is

total Cash: 30
total Charge: 200
totaL Invoice: 50
Grandtotal :280

I can already get the Grandtotal but i can find a way to get the total cash,charge and invoice

what query should i use..? do i need a computation to achieve this?what is the best and easiest way to do it..?without affecting much in my current sql queries

thanks in advance

Member Avatar for Rahul47

You need to be more specific. Your question requires more explanation. Please post with some snapshot.

From where is total cash, total charge, total invoice coming from ?

sorry about that im trying to add snapshot on my post but its not showing.ill try again

the total cash, total charge, total invoice came from a specific date range that the user search in the db

81ee817681926b9e83546dc84732b528

weired the snapshot is not clickable i'll attached it again here

Member Avatar for Rahul47

You need to attach it as file.

ok here it is

67870ab9c4b2542f15c07c430e61a08f

Member Avatar for Rahul47

I still cannot see that image properly.

Member Avatar for Rahul47

Right now I can only think of computation like you did for total. But then your code will be bulky.

P.S: Always try to explain your doubt in depth. :-)

Thanks for the link although i already found a way to do it..i made it playing around with my while loop and query like this

$sql = "SELECT Payment_type, sum(Grand_total) type_total FROM advance WHERE SDate BETWEEN '" . $from . "' AND '" . $to . "' GROUP BY Payment_type";
$result = mysql_query($sql);
while($row = mysql_fetch_array( $result )){


echo"<tr colspan='3'><td align='center' >Total ".$row['Payment_type']."</td><td align='center' width='1000px';>".$row['type_total'] ."</td></tr>";

}
echo"<tr colspan='3'><td align='center' >Grand Total</td><td align='center'>$total</td></tr>";

a lil bet messy but it make the work done

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.