june_c21 Posted November 2, 2007 Share Posted November 2, 2007 hi, i am new in php. i want to write a program that calculate 'claim'. 400 people going to input their claims using forms into database. 1 person might got 3 claims another might got 6 claims. now i want to calculate the total amount of each individual claims and display it. how to write this ? Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/ Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 Just add the items $total = $item1 + $item2 + $item3; echo "£" . money_format('%i' , $total); Desmond. Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383516 Share on other sites More sharing options...
Solarpitch Posted November 2, 2007 Share Posted November 2, 2007 Why not just store the claims in a seperate table in the database. Table called "claims". In that store all the information relating to claims and reference the user id in it to their particular claim. ID USERID CLAIM AMMOUNT 1 241 €6000 2 245 €5650 3 245 €9000 4 154 €20000 Then use what Desmond said about adding and displaying Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383522 Share on other sites More sharing options...
june_c21 Posted November 2, 2007 Author Share Posted November 2, 2007 difference user got different number of claim. total of the claim must based on user's name. example name claim A 200 B 300 A 200 A 150 B 200 Report name total A 550 B 500 Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383523 Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 You would probably need a field ClameID as each claim could have a diffrent number of items Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383524 Share on other sites More sharing options...
june_c21 Posted November 2, 2007 Author Share Posted November 2, 2007 ok but how to do the total up? Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383526 Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 Asume you have 2 tables *customer* CusomerId Name Address Phone *claims* ClameID CustomerID Value $total = 0; $SQL = "SELECT Value from claims WHERE ClaimID = 35"; $rsEvents = mysql_query($Events) or die(mysql_error()); while ($row = mysql_fetch_array($rsEvents)) { $total += $row[Value]; } echo "£" . money_format('%i' , $total); Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383531 Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 Sorry to eager to cut and paste $total = 0; $SQL = "SELECT Value from claims WHERE ClaimID = 35"; $rs = mysql_query($SQL) or die(mysql_error()); while ($row = mysql_fetch_array($rs)) { $total += $row[Value]; } echo "£" . money_format('%i' , $total); Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383534 Share on other sites More sharing options...
Barand Posted November 2, 2007 Share Posted November 2, 2007 total of the claim must based on user's name. I would advise allocation each person a unique id number and basing the claims on those. You may have two "John Smiths" but they would have unique ids to keep their claims separate. As for totalling: id name claim 1 A 200 2 B 300 1 A 200 1 A 150 2 B 200 A simple query SELECT id, name, SUM(claim) FROM claims GROUP BY id, name will give the total for each person. Link to comment https://forums.phpfreaks.com/topic/75779-solved-arithmetic-operator/#findComment-383684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.