$sth = $dbh->prepare (qq{ SELECT * FROM table_name ORDER BY bid }); $sth->execute(); while ($row = $sth->fetchrow_hashref()) { $tracked_impressions = 0; $tracked_clicks = 0; $tracked_sales = 0; $sth1 = $dbh->prepare (qq{ SELECT * FROM aff_trac WHERE id = $aff_id AND bid = $row->{bid} AND t BETWEEN "$database_query_date_s" AND "$database_query_date_e" }); $sth1->execute(); while ($aff_row = $sth1->fetchrow_hashref()) { if ($aff_row->{utype} =~ /^i$/) { $tracked_impressions++; } elsif ($aff_row->{utype} =~ /^h$/) { $tracked_clicks++; } elsif($aff_row->{utype} =~ /^s$/) { $tracked_sales++; } } $html_content .= qq~ Advertisement ID: $row->{bid} Program ID $row->{bid}
Impressions: $tracked_impressions Clicks: $tracked_clicks Click Through Rate: ~; if ($tracked_click || $tracked_impressions) { $html_content .= ($tracked_click*1) / ($tracked_impressions*1); } else { $html_content .= "1000"; # Temp so I can see when it did NOT work... or there was 0 to track... } $html_content .= qq~% Sales: $tracked_sales:
\n~; } $dbh->disconnect();