Gossamer Forum
Home : Products : DBMan : Customization :

totalling in view_search

Quote Reply
totalling in view_search
Hi,

I maintain a small hours registration database for a couple of freelancers. On the view_succes page I inserted a box with totals for a search action in the database. It works, but only when I'm not searching for either field 7 or field 1 in view_search. In these cases a value of 0 is returned, when it should be 'hours * fee = total fee'.

Basically, I want to calculate how many hours (stored in field 1) each freelancer (stored in field 7) has worked, and then multiply the totalled working hours by each freelancer's hour fee (hardcoded, not stored in the database). I only need it for printing, nothing needs to be stored in the db.

Code:


# begin totalen

# change the values below to match the field numbers of your name and amount fields

$Door = 7;

$Uren = 1;



for (0 .. $numhits - 1) {

$name = $hits[$_ * ($#db_cols+1) + $Door];

$amount = $hits[$_ * ($#db_cols+1) + $Uren];

if ($name eq "A") {

$amount2 = $amount * 20;

}

elsif ($name eq "B") {

$amount2 = $amount * 18;

}

elsif ($name eq 'C') {

$amount2 = $amount * 21;

}

elsif ($name eq 'D') {

$amount2 = $amount * 17;

}

$total{$name} += $amount;

$total_bedrag{$name} += $amount2;

$grand_total += $amount;

$grand_total_bedrag += $amount2;

}

foreach $key (sort keys %total) {

print qq|

<tr><td>

<$font><b>$key</b></font>

</td><td>

<$font>$total{$key}</font>

</td><td><$font>$total_bedrag{$key},-</font>

</td></tr>

|;

}

print qq|

<tr><td colspan=3>

======================

</td></tr>

<td><$font>

<b>Totaal</b></font>

</td>

<td>

<$font>$grand_total</font>

</td>

<td>

<$font>$grand_total_bedrag,-</font>

</td></tr>

</table>

|;

# einde totalen



T.i.a., peter
Quote Reply
Re: [peter01] totalling in view_search In reply to
Have you by any chance searched the FAQ? Under the section 'Calculate' there are several related threads.

The one titled "Subtotalling Search Results" look like it would help to provide solutions. Be sure to check others also as you may come up with various options and ideas.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] totalling in view_search In reply to
Code:


Hi,

As a matter of fact I'm pretty sure I ripped the code above from that thread. It's only that I can't find any info here or on your FAQ about what variables to use in the string that prints out the results. The $key variable that I use now returns a value of 0 when I search on one the fields that is reassigned to another variable ($Door and $Uren) at the beginning of the code above.

Last edited by:

peter01: Oct 8, 2002, 5:47 AM
Quote Reply
Re: [peter01] totalling in view_search In reply to
I'm not a programmer so I'm not able to help you find your solution. You best bet would be to locate all the other related threads for doing calculations in the FAQ, under both that section, and also in the section "Viewing". I'm pretty sure there are other threads which will help you, but I don't specifically know which ones.

I also know there may be other places within the script (db.cgi file) to adjust for calculations from my own experience.

It may also help to search the GT forum for any other threads by the user that provided the codes you are attempting to see if there is more information available.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/