Gossamer Forum
Home : Products : DBMan : Customization :

Adding Fields Together

Quote Reply
Adding Fields Together
Racking My Brain!!!!! Please Help :-)
I would like to know how to add two fields together and store the value in another variable I can display.

ie Feild_Total = Field_1 + Field_2

Quote Reply
Re: Adding Fields Together In reply to
I'm going to assume that you want to add two fields from the current record together and that you are not interested in saving the total into a third field.

In html.pl, sub html_record, after

my (%rec) = @_;

add

$total = 0;
$total = $rec{'FieldName1'} + $rec{'FieldName2'};


(Naturally, you would replace FieldName1 and FieldName2 with the actual names of your fields.)

Then use the variable $total wherever you want the total to print out.


JPD
Quote Reply
Re: Adding Fields Together In reply to
If I did wish to save it to a new field?

Now that you bring up why not ask.........
Quote Reply
Re: Adding Fields Together In reply to
Code:

$rec{'FieldName'} = $in{'Fieldname2'} + $in{'Fieldname3'};


in the sub add_record routine in the db.cgi file.

Regards,

Eliot Lee
Quote Reply
Re: Adding Fields Together In reply to
After putting that line in db.cgi what steps do I have to follow in html.pl or default.cfg???

Becuase I did that and the variable Fieldname disspears....
Quote Reply
Re: Adding Fields Together In reply to
In Reply To:
After putting that line in db.cgi what steps do I have to follow in html.pl or default.cfg???
You shouldn't have to add anything in your html.pl file.

Make sure that you are using the correct fieldnames.

Regards,

Eliot Lee
Quote Reply
Re: Adding Fields Together In reply to
Eliot was close, but not quite. The code you need to add to sub add_record is

$in{'FieldName'} = $in{'FieldName1'} + $in{'FieldName2'};

Put it just before the line

$status = &validate_record;




JPD