Gossamer Forum
Home : Products : DBMan : Customization :

displaying correct results

Quote Reply
displaying correct results
Frown Hi, I have a DB setup with 4 field, the fields are called ID, month_year, product and total_order. I'm have been trying to (with no luck) to display the record so for each product I get a month by month total.
eg.
1|May_2006|Apples|2
2|May_2006|Apples|3
3|Jun_2006|Oranges|2
4|Jun_2006|Oranges|3
5|Jul_2006|Pears|2
6|Jul_2006|Pears|3
.
.
etc
I'm trying to display so the results looks like
product May_2006 Jun_2006 Jul_2006...dec_2006
Apples 5 5 5
Oranges 5 5 5
Pears 5 5 5
and so on for each product and month/year

Here is the code I have been trying to get to work.
open (DB, "<$db_file_name") or &cgierr("error in count. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB,1); }
@lines = <DB>;
close DB;
foreach $line (@lines) {
chomp ($line);
@data = &split_decode($line);
++$count{$data[27]}; # months
$month{$data[5]} += $data[9];
$actual{$data[5]} += $data[9];
++$count;
}

for ($i = 1; $i<=52; ++$i) {
print qq|$i : $month{$data[27]} : $month{$i} : $actual{$i}<BR>|; }
Any help or advise in the right direction would be great appreciated as I have tryed every combination.

Quote Reply
Re: [colinw] displaying correct results In reply to
FWIW try checking out the unofficial FAQ maintained by LoisC at www.redundantcartridge.com/dbman - search for "grouping" and "categories" that may help point you in the right direction. There's also some topics on sorting by more than one field (sort by year, product then total or so (?).

If you want help with the code you posted try www.perlguru.com - the help won't be specific to dbman, but they'll be able to help you spot what's wrong with your code.