Gossamer Forum
Home : Products : Links 2.0 : Customization :

Calculating a grand total

Quote Reply
Calculating a grand total
Hello,

I added to my database a numeric field and I would like to display on the home-page the current grand-total on this field for ALL of the records in the database

Anyone has a simple method to solve this?
Thanks a lot

Quote Reply
Re: Calculating a grand total In reply to
Just wanted to keep your Thread towards the top of the forum....I am working on a similar code hack in my site. If and when I come up with an easy solution, I will post it...

Regards,

Eliot Lee
Quote Reply
Re: Calculating a grand total In reply to
Hello,

Thanks for your post, and I'm keeping this thread up with this reply.

The requested mod should i.e. display in the home page the TOTAL number of hits cumuled, by adding all %Hits% field on link records.

This should be pretty easy for you PERL masters..? :-)
Thanks again for any help


Quote Reply
Re: Calculating a grand total In reply to
Welp...still working on it....but my code hack is much more complicated...I am working on different calculations between fields (hits, email recommendations, nominations, etc.) during the month to automatically have the script make recommendations for which sites to be listed as "Sites of the Month".

Wink

Regards,

Eliot Lee
Quote Reply
Re: Calculating a grand total In reply to
Okay...I figured out how to get the following calculations:

1) Total Hits
2) Most Hits
3) Least Hits

that can be posted in the Home Page. (Thanks to Widgetz's sub get_reviews routine codes.)

This is NOT an easy code hack to implement...please save a copy of the following files before hacking:

1) nph-build.cgi
2) site_html_templates.pl

Okay...here we go...Ready?

(1) Add the following codes in the sub build_stats routine in the nph-build.cgi file:

Code:

$grandhits{$values[$db_hits]}++;
$hitstotal += $values[$db_hits];
$grandhits++;
if ($lowest > $values[$db_hits]) {
$lowest = $values[$db_hits];
}
else {
$lowest = "0";
}
if ($highest < $values[$db_hits]) {
$highest = $values[$db_hits];
}
else {
$highest = "Not Calculated";
}


AFTER the following codes:

Code:

$category = $values[$db_category];


(2) Then replace the following codes in the sub build_home_page routine:

Code:

local ($total);


with the following codes:

Code:

local ($total, $totalhits, $lowhits, $highhits);


(3) Then add the following codes in the same sub-routine:

Code:

print "\tTotal Hits: $hitstotal\n";
print "\tMost Hits: $highest\n";
print "\tLeast Hits: $lowest\n";


AFTER the following codes:

Code:

print "\tTotal Links: $grand_total\n";


(4) Then add the following codes in the same sub-routine:

Code:

$totalhits = $hitstotal;
$lowhits = $lowest;
$highhits = $highest;


AFTER the following codes:

Code:

$total = $grand_total;


(5) Then add the following tag definitions in the sub site_html_home routine in the site_html_templates.pl file:

Code:

totalhits => $totalhits,
lowhits => $lowest,
highhits => $highest


(6) Then add the following tags in your home.html file:

Code:

<%totalhits%>
<%lowhits%>
<%highhits%>


That should do it....

BTW: I have this working in my Anthropology portal site:

http://vlib.anthrotech.com

Regards,

Eliot Lee
Quote Reply
Re: Calculating a grand total In reply to
Very cool!!
Thanks a lot Eliot

Quote Reply
Re: Calculating a grand total In reply to
You're welcome....

BTW: I also added:

Votes:

* Total
* Range (lowest to highest)

Ratings:

* Total
* Range (lowest to highest)

Not to hard to do if you know anything about $db_col and also variables. The codes I gave can be adapted to add these statistics.

Smile

Regards,

Eliot Lee
Quote Reply
Re: Calculating a grand total In reply to
I am having a small problem with the hack above.

when I have just one link in the database i get this.

Code:
Total Hits 50
Least Hits 0
Highest 50
But when I try to add more links I get this

Code:
Total Hits 50
Least Hits 0
Highest Hits Not Calculated
has anybody else had this problem?

Quote Reply
Re: Calculating a grand total In reply to
Does anyone have any ideas?

Quote Reply
Re: Calculating a grand total In reply to
Eliot,

I am trying to do the same for the grand total of votes but no success. Any idea?

Thanks.


Regards,

Pagla

Quote Reply
Re: Calculating a grand total In reply to
Uh...replace $db_hits with $db_votes and then rename the
other variables in the codes I've posted above...it is not that hard to
hack....

Regards,

Eliot Lee
Quote Reply
Re: Calculating a grand total In reply to
 
I did but no number is showing. What am I doing wrong?

Thanks.


Regards,

Pagla

Quote Reply
Re: Calculating a grand total In reply to
 
Thanks again Eliot. Problem solved. I even got avarage votes by adding the following

$averagevotes = int($totalhits/$totalvotes);

I hope this is right?



Regards,

Pagla