Home : Products : DBMan SQL : Discussion :

Products: DBMan SQL: Discussion: How many books in each category ?: Edit Log

Here is the list of edits for this post
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

Edit Log: