htmanning has asked for the wisdom of the Perl Monks concerning the following question:
The only thing I could think of to do was to create a $threadIDlist. Each time I loop through I check the threadIDlist to see if the current threadID is on the list. If it is, I skip it otherwise I print that row then add the current threadID to the list. There must be a better way to do this but this is where I am:
$rows=$sth->rows; while (($pointer = $sth->fetchrow_hashref) && ($current_count +_all <= $stopcount_all)){ $threadID = $pointer->{'threadID'}; if ($threadIDlist !~ /$threadID/) { $threadIDlist=$threadID . "," . $threadIDlist; $threadcount++; #print message list here } }
It works, BUT I need to know the total number of threadIDs. When I count the number of rows it gives me the total number of rows (128) not the number of threadIDs.
The only thing I could think to do was to do this same loop BEFORE I start printing the list so I could track the $threadcount. I'm assuming that's a pretty lame way of doing it.
If my explanation makes sense, can someone give me a better way to grab the total number of threads without having to loop through twice?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting fields from database (updated)
by haukex (Archbishop) on Oct 02, 2020 at 21:49 UTC | |
by htmanning (Friar) on Oct 03, 2020 at 00:49 UTC | |
by htmanning (Friar) on Oct 03, 2020 at 01:31 UTC | |
by haukex (Archbishop) on Oct 03, 2020 at 07:29 UTC | |
by htmanning (Friar) on Oct 03, 2020 at 21:34 UTC | |
|
Re: Counting fields from database
by wazat (Monk) on Oct 02, 2020 at 23:53 UTC | |
by htmanning (Friar) on Oct 03, 2020 at 00:50 UTC | |
by BillKSmith (Monsignor) on Oct 03, 2020 at 18:29 UTC | |
|
Re: Counting fields from database
by Anonymous Monk on Oct 03, 2020 at 14:22 UTC | |
by Anonymous Monk on Oct 05, 2020 at 16:22 UTC |