Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Is it possible to add values of particular fields for multiple links?

Quote Reply
Is it possible to add values of particular fields for multiple links?
 
Suppose I add a user-property field called 'amount_recovered'.
[type = BIGINT
index = Regular (I think) ]


How to calculate total for amount_recovered field for:
  1. Display value of 'amount_recovered' from user profile details in link.html & detailed.html page?

  2. Display total for 'amount_recovered' for all links any single category.

  3. Display total for 'amount_recovered' for all links for any desired category & all sub-categories under it.

  4. Display total for 'amount_recovered' for Entire website.



Example:
For a legal directory, I will be asking law-firms to input $ amount for the cases they have won/setteled so far.


Usage:
  1. So for the category of Dallas, I want to have the ability to display 'Grand Total' of 'amount_recovered' all the listings in Dallas Category.

  2. While for Texas (parent category of Dallas & all other cities in Texas), ideally I want to be able to display grand total of all.
    .. note: there might be few users who will have multiple listings, as some law-firms have offices in different cities. So in this scenario, we want to avoid doing multiple total additions.

  3. Ability to display grand total for all links in the entire directory.

  4. Ability to display grand total for all links . (or I suppose I should saw, grand total for all users)


Thank you.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] Is it possible to add values of particular fields for multiple links? In reply to
Hi,

Do you also have "amount_recovered" in the Links table? Or is it just allocated to the Users table, and you want to use LinkOwner to do the math for category totals?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [VishalT] Is it possible to add values of particular fields for multiple links? In reply to
Hi,

So the most efficient way of doing this would be to start with a new script: get_overall_totals.cgi - with:

Code:
#!/usr/bin/perl

use strict;
use lib '/path/to/admin';
use Links qw/$IN $DB $CFG/;

local $SIG{__DIE__} = \&Links::fatal;

Links::init('/path/to/admin');

my $sth = $DB->table("Category")->select();

while (my $cat = $sth->fetchrow_hashref) {
my $total_amount = $DB->table('Links','CatLinks')->select ( ['SUM(YOUR_FIELD_NAME)'], { CategoryID => $cat->{ID} })->fetchrow;
$DB->table("Category")->update( { total_figure => $total_amount }, { ID => })
}

my $sth = $DB->table("Users")->select();

while (my $user = $sth->fetchrow_hashref) {
my $total_amount = $DB->table('Links')->select( ['SUM(YOUR_FIELD_NAME)'], { LinkOwner => $user->{Username} })->fetchrow;
$DB->table("Users")->update( { total_figure => $total_amount }, { ID => })
}

This relies on a field in your Links table, and Category table called "YOUR_FIELD_NAME" (name itas you want obviously)

Just run this from SSH with:

perl get_overall_totals.cgi

This should populate each category with the correct values, and also the users table. For the categories, it won't add up sub-categories but that's easy enough with another global if this bit works for you

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Is it possible to add values of particular fields for multiple links? In reply to
I am the one managing it & creating it.. so I can create all the tables that would be needed :)..

At first I was thinking of creating the table under link-properties. however after noticing the possible duplicate total issues (since one law firm can have multiple offices in each state & sometimes even in same city), I was thinking it would be better to have the field under user-properties.

Vishal
-------------------------------------------------------
Quote Reply
Re: [Andy] Is it possible to add values of particular fields for multiple links? In reply to
will work on testing this out.. :)

I have not added external/additional script/files in GLinks before.. but there is always a first time for everything..

Thank you Andy. :) :)

Vishal
-------------------------------------------------------