You wrote:
for ( scalar $rows_data ) { $sth2->execute($_); my $count = $sth2->fetchrow_array; push @$rows_data, { count => $count }

1. Where does $rows_data come from? It looks like an arrayref, so you should treat it as such. Are you trying to get the number of elements in it, or are you iterating over it? If the former, then do  for( scalar @$rows_data ); if the latter, do for( @$rows_data )
2. Pushing new values onto an array you're iterating over is likely to confuse the for() loop, and won't do what you want. Try using a new array for your hashrefs.

That being said, are you sure one of Class::DBI's count() methods or one of the Count plugins won't be able to do this for you more effeciently?
It's not entirely clear what you are trying to put together. Could you give us a better description of your data model, and your desired output model?


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.