Got a doozy here. Part of the web reporting that Mgmt wants includes a running list of subscribers to our newsletter.
Background - I'm running Linux/Apache with FreeTDS/DBD::Sybase connecting to a Win2K box with SQL Server 7.0.
Every time someone subscribes they put in their address (specifically the State they live in) and the DB includes the date/time they subscribed.
Sample record:
Col 1 - John Smith Col 2 - NY Col 3 - 02/06/2003
I print to screen the top ten states and the count of subscribers in descending order.
Example
Jan Feb Mar
New York 115 0 0
Florida 34 0 0
Georgia 28 0 0
Here's how I do it.
my $sth = $dbh->prepare("SELECT DISTINCT state, COUNT(*) FROM con
+tacts WHERE state != '' AND identifier BETWEEN '2003-01-01' AND '2003
+-02-01' GROUP BY state ORDER BY 2 DESC");
$sth->execute() or die $sth->errstr;
my $rows = 0;
while (my @result = $sth->fetchrow_array()) {
last if $rows++ >= 10;
print qq(<tr><td><p style="margin-left: 10"><font size="2" face="
+Arial">$result[0]</font></td><td><div align="right"><font size="2" fa
+ce="Arial"> </font></div></td><td><font size="2" face="Arial"><d
+iv align="right">$result[1]</div></font></td><td><div align="right"><
+font size="2" face="Arial">0</font></div></td><tr>\n);
}
$sth->finish();
But how can I do this for the following months?
Here's what I need it to look like.
Jan Feb Mar
New York 115 100 0
Georgia 28 45 0
Florida 34 10 0
I need the order to be listed by the current month and still show what happened the previous months.
Can anyone help point me in the right direction?
peppiv
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.