Gossamer Forum
Home : Products : DBMan : Customization :

Calculating

(Page 1 of 2)
> >
Quote Reply
Calculating
Hi,

I read through some posts but I'm a little unclear on how to bring things together for what I need done.

I have a database that would look like this:
Userid Field1 Value1
xyz item1 100
xyz item1 100
xyz item2 200
abc item1 100
cdf item2 200
cdf item2 200
cdf item3 300

I need to display to only the owner of the record the following info when they call for it:
item1 = ______
item2 = ______
item3 = ______
total = ______

So for my example:
xyz would display to themselves:
item1 = 200
item2 = 200
item3 = 0
total = 400

abc would display to themselves:
item1 = 100
item2 = 0
item3 = 0
total = 100

cdf would display to themselves:
item1 = 0
item2 = 400
item3 = 300
total = 700

This information does not need to be written back to the database, only displayed when called for.

Does this make any sense?

Thanks in advance!
Adam

Quote Reply
Re: Calculating In reply to
This is not a solution, just adding to the problem I guess, Im sorry if this bothers you, I really do wish i had a solution for you.

I need to do the same thing, but a bit more complex.
Feild = F

I need to be able to do entire equations, such as 100(f4*10(f3) +f5/2) = F8 Feild * would not need to be written, althought it would be nice, as long as the users can not change it, but it would really help out with the calculations that i have to do by hand right now, anyone have some help on our problems? Thanks

Quote Reply
Re: Calculating In reply to
I know I have seen thread similiar to what you are looking and may have them references in the FAQ noted below.

Reading through the previous thread that dealt with calculations may help you find a solution or provide ideas.

Look under "Calculate / Counts" and hopefully one of the solutions will what you are both looking for.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Calculating In reply to
This one seems to be somewhat the same idea.....however not quite and I'm a bit unsure how to take this to get to where I need to be.

http://webmagic.hypermart.net/dbman/calc05.txt

Adam

Quote Reply
Re: Calculating In reply to
adam:

I'm only on for a few minutes this morning, but will continue to search this afternoon to try and find the thread I think will provide your solution.

I do rememeber someone trying to do what you want and was hoping I could find it in the FAQ, but perhaps it's one that I still have filed so I could condense the thread.

I promise I will look and see if I can locate it for you.


Okay i did some searching through my notes and it really looks like calc05.txt would be your best bet to use as a guide for getting the results you need, but there is another thread which may work also.

Try the following:

http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000496.html

Topic: "Total amount = ???" #Add all amounts and print it as a search result ?
koreags - posted July 11, 1999

I hope this will help you Smile

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Calculating In reply to
I got mine from the FAQ, took some interesting scripting but got it..thanks for the tip.

Quote Reply
Re: Calculating In reply to
Ulic:

So glad to hear you found your solution.
The calculations was one section I wish I had more information for Smile


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Calculating In reply to
JPD,

Just bringing this back to life since I think I'm ready for it!

Thanks!

Adam

Quote Reply
Re: Calculating In reply to
Okay. Here goes.

Let's start with just getting a grand total.

After

for (0 .. $numhits2 - 1) {

add

$grand_total += $rec2{'Value1'};

(assuming, of course, that your field name is Value1 change that as needed.

Then, after the loop finishes, add a line to print out the total, using the $grand_total variable. Pretty simple, huh? Smile

When you've got this working, we can go to the other thing of having subtotals. A couple of questions I'll need you to answer.

Do you have the "many" search results sorted by the "Field1" field?

How do you want users to select which display they wish to see?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
First I just realized something. How will this handle negative numbers? Or would it be easier to have two value fields.....All numbers for that particular user in Value1 are added to the grand total, and all numbers for that particular user in Value2 are subtracted from the grand total. For a single record one field will have a value and the other field will be 0.

Adam

Quote Reply
Re: Calculating In reply to
Oh. Okay.

Well, you can use the same type of syntax

$grand_total += $rec2{'Value1'};
$grand_total -= $rec2{'Value2'};


(I made a typo earlier. The + sign was on the wrong side of the = sign. I'll change it in my previous post.)


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
It's not working. I'm returning $grand_total=0

I have tried a few different things....but I'm not sure what's wrong.

Adam

Quote Reply
Re: Calculating In reply to
Move the "totaling" lines down to after the line that has &array_to_hash on it.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
I'm still coming back with 0's.

Let's do this. How about if we write a seperate section.

sub grand_total {
}

And to answer your other questions......
I am not sorting the records.
Two links. One for itemized and one for aggregate.
Quote Reply
Re: Calculating In reply to
Can you post sub html_record here? I sort of feel like I'm fumbling in the dark here. Smile

Or you can post it on the web and tell me where it is.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
I believe you have been thinking about this in terms of the relational. I would prefer to have the code as it is edited from the released dbman.

Esentially, I want to forget about the relational setup I did before, only because I modified it a bit and that really applies to a lot I am doing. It's complicated.......(not the code, just my rational) Smile

Does that work? Consider the original html.pl & db.cgi

Adam

Quote Reply
Re: Calculating In reply to
I can't tell what's wrong unless I look at the code.

One way or another (even if you don't use my method) what you're working with is a relational database. You have one record in one database file that is related to multiple records in another database file. That is the definition of a relational database.

It won't hurt my feelings if you decided to use something other than what I gave you. But it seems that what you're using isn't working, so I need to see what you're using in order to see why.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
I understand what you're saying. The issue is, I need the code also for the a db that is not relational. Thus, if I have that one working properly then maybe the other will fall into place.

I would prefer starting with modding the original (and easier) before going through my mess..... that's all.

Adam

Quote Reply
Re: Calculating In reply to
Okay, I guess.

The way to total the values of a field in a number of records, is, as you go through the records, you add them to a variable.

There are two ways to add values to a variable:

$grand_total = $grand_total + $new_value;

or

$grand_total += $new_value;

Both of those lines do exactly the same thing. You can also subtract, multiply and divide by using similar syntax.

You would want your line that totals to be after the @hits array has been converted into the %rec hash, and the "$new_value" would be $rec{'FieldName'}.

I don't know what else to tell you. Without having any specifics to go by, I can't give you anything but a general idea of what to do.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
[edited]
Now i'm understanding...

So in the original html.pl would the calculation need to be put
After my (%rec) = @_; in the html_record

And the print out of the total would be
After &html_record (&array_to_hash($_, @hits)); in the html_view_success

Thanks,
Adam

Quote Reply
Re: Calculating In reply to
My new thread will probably answer some of your questions as to my setup. It's really messed up!
Since I am using templates it makes mods a little harder to work with, but I have been successful so far with all that I needed to do.....until now Frown

Adam

Quote Reply
Re: Calculating In reply to
Right. Well, sorta.

The printout of the total would have to be after

Code:

&html_record (&array_to_hash($_, @hits));
}
Gotta get out of the "for" loop first.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating In reply to
Right! Got out of the loop...just forgot to include it in my post.

Hmm....a running subtotal........????

Quote Reply
Re: Calculating In reply to
Sure enough!

Inside the loop is a subtotal....outside the loop is a grand total!!!

Smile

Your explanation of how the adding works did wonders for me!
Smile
Thanks!
Adam

Quote Reply
Re: Calculating In reply to
I finally got it. After getting it to work in the original html.pl I was able to get it to work in my highly modified templates version as well.

So all is well in my land Smile

Thanks JPD! I really appreciate all your help and patience.
Adam

> >