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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.