in reply to Re: retrieving the reply count of a thread using regular ol' DBI and CGI::Application
in thread retrieving the reply count of a thread using regular ol' DBI and CGI::Application

This doesn't account for the first SQL query from which I obtain the id's of the original threads however.

What i need is to retrieve the messages, and from that take the id and pass it through the second SQL query from where i get the COUNT(*). This count up the total replies that have a thread_id that matches the id passed through the ->execute()

meh.
  • Comment on Re^2: retrieving the reply count of a thread using regular ol' DBI and CGI::Application
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: retrieving the reply count of a thread using regular ol' DBI and CGI::Application
by Excalibor (Pilgrim) on Oct 11, 2005 at 13:55 UTC

    This works for me:

    use DBI; my $dbh = DBI->connect("dbi:SQLite:dbname=count.db","",""); my $sth1 = $dbh->prepare('select id from threads'); my $sth2 = $dbh->prepare('select count(*) from replies where thid = ?' +); $sth1->execute; for my $thid ( @{$sth1->fetchall_arrayref} ) { print "Thread: ", $thid->[0], "...\n"; $sth2->execute($thid->[0]); print "Replies for thread ", $thid->[0], ": ", $sth2->fetchrow_arr +ay, "\n"; } $sth1->finish; $sth2->finish; $dbh->disconnect; __END__ SQL Schema: sqlite> create table threads ( id integer primary key, title varchar(2 +56) ); sqlite> create table replies ( id integer primary key, thid integer, t +itle varchar(256) ); sqlite> insert into replies values (1, 1, 're: test1' ); sqlite> insert into replies values (2, 1, 're: re: test1' ); sqlite> insert into replies values (3, 2, 're: test2' ); sqlite> insert into threads values (1, 'test1'); sqlite> insert into threads values (2, 'test2'); Execution: $ perl test_count.pl Thread: 1... Replies for thread 1: 2 Thread: 2... Replies for thread 2: 1 $

    Maybe your setup is different, but you should be able to translate appropriately...

    Best regards...

    --
    our $Perl6 is Fantastic;

      This is the closest to what I was actually thinking of doing out of these threads...I'm sure faster than what I have posted as well

      meh.