Gossamer Forum
Home : Products : DBMan : Customization :

Aggregating/searching results

Quote Reply
Aggregating/searching results
I'm attempting to add a little functionality to a DBMan database and have run into a snag. How can I search the returned search results to come up with results totals? My database will have the date, score, opponent, and result of a hockey team's games. [Go to http://cgibin.erols.com/...d=&view_search=1 to see what I have so far.] When results are returned, I'd like to then be able to show the combined record (Won-Lost-Tied) at the top of the page based on the search criteria. I've tried putting the following in the sub html_view_success of the html.pl file with no luck:

$games_won=0;
for (0 .. $numhits - 1) {
if ($rec{'Result'} eq "Won") {
$games_won++;
}
}

Any ideas/suggestions? Thanks in advance for any help.
Quote Reply
Re: Aggregating/searching results In reply to
In order for that to work you have to first use a "&array_to_hash" call:

Code:
$games_won=0;
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{'Result'} eq "Won") {
$games_won++;
}
}


------------------
JPD

All my advice is offered on the basis of kindness-ware. If I've helped you to solve a problem, go out of your way to be kind to someone today.

Quote Reply
Re: Aggregating/searching results In reply to
Thanks! Almost there. That works for the records on the current page but is there a way to count all the records which were returned over multiple pages?

I tried using:

$games_won=0;
for (0 .. $db_total_hits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{'Result'} eq "Won") {
$games_won++;
}
}

but it is still only counting the records that are on the current page. For example, if I do a search on all games played in the 1967-68 season, it returns 74 total matches and is showing that 8 games were won. 8 games were won in the first 20 games of that season but actually the Penguins won 27 games total that season.

Thanks again!
Quote Reply
Re: Aggregating/searching results In reply to
You won't have access to all the results in @hits, so you have to go into &query in db.cgi to do the counting. Right after:

$numhits++; # But we always count it!

add:

$db_game_wins++ if ($values[4] eq 'Yes');

(where 4 is the field number that corresponds to field name 'Result').

Then you can get the total wins by using $db_game_wins.

Cheers,

Alex
Quote Reply
Re: Aggregating/searching results In reply to
JPDeni and Alex,

Thanks to both of you for your replies! It's now working like a charm. I had to go with
$db_games_won++ if ($values[4] =~ /Won/); due to overtime games.

I can now tell you that the Pens' record vs the Vancouver Canucks is 32-20-7 through the 1983-84 season (haven't gotten 1984-present in yet...) or that it's 15-13-3 at Vancouver or that it's 3-0-1 at Vancouver in October etc., etc., etc.

Thanks again!