Gossamer Forum
Home : Products : DBMan SQL : Discussion :

How many books in each category ?

Quote Reply
How many books in each category ?
Hi all !

I attempt to create simple (but hard for me :) global, which will calculate quantity of books in each category in categories list (bookstore template in DBMan SQL).

Something like this:
-------------------------
Fantasy - 156
Detective - 321
Psychology - 527


Now (after three days, about a hundred read threads and repairing my PC), I have two parts of this:

First, the global that makes categories list:
----------------------------------------------------
sub {
my $tags = shift;
my $table = $DB->table('Category');
my $sth = $table->select (['CatName','CatID']);
my $output;
my $num;
while (my $row = $sth->fetchrow_hashref){
$num = $num + 1;
($output .= "<font face=\"verdana,arial,helvetica\" size=\"-2\"><a href=db.cgi?&sid=$tags->{session_id}&db=Book&do=search_results&CatID=$row->{CatID}>$row->{CatName}</a></font><br><br>\n");
}
return $output;
}


Second, the global that counts number of books in separate category:
-----------------------------------------------------------------------------------
sub {
$DB->table('Book')->select('count( DISTINCT(Title) )' =>GT::SQL::Condition->new('CatID', 'LIKE', '1'))->fetchrow
}


I've tried thousands different methods, attempting to connect these parts, but in vain :(
I've read the GT Module Documentation (Tables, Conditions and other useful stuff) five times! Now I feel myself almost like a real programmer, but all the same I can't understand, HOW it should be made.
Whether somebody can give me small advice on this problem?

Regards,

Paul

Last edited by:

Skiff: Apr 24, 2003, 1:28 PM
Subject Author Views Date
Thread How many books in each category ? Skiff 2916 Apr 24, 2003, 1:14 PM
Thread Re: [Skiff] How many books in each category ?
604 2843 Apr 25, 2003, 9:30 AM
Thread Re: [TheStone] How many books in each category ?
Skiff 2824 Apr 25, 2003, 7:00 PM
Thread Re: [Skiff] How many books in each category ?
604 2800 Apr 28, 2003, 12:19 PM
Post Re: [TheStone] How many books in each category ?
Skiff 2799 Apr 28, 2003, 1:18 PM