Jump to content

[SOLVED] Arithmetic operator


june_c21

Recommended Posts

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

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

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

 

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);

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.