I would appreciate any help you can be.sub show_heavy_hitters { my $_view = $in{view}; if($_view && $_view eq "view_here") { my %states = Build_Hash("statecodes",""); $in{nw} = 1; # Show in New window format so that the table won +'t make main table stretch my $sth = $dbh->prepare(qq{SELECT * FROM `member_records`}); $sth->execute(); my @row = (); push(@row, Tr( th("Date Registered"), th("Username"), th("Name"), th("Phone"), th("State"), th("Referrals") ) ); while(my $_t1 = $sth->fetchrow_hashref()) { my $sth2 = $dbh->prepare(qq{SELECT * FROM `shipping_addres +s_records` WHERE `id` = ? AND `default` = ?}); $sth2->execute($_t1->{id},"1"); my $_s1 = $sth2->fetchrow_hashref(); $sth2->finish(); my $_state = $_s1->{state}; $_state = $states{$_state}; if($_state && $_state =~ /Other /) { $_state = $_s1->{o_state} if $_s1->{o_state}; } my $_num_referred = $dbh->selectrow_array(qq{SELECT COUNT( +*) FROM `member_records` WHERE `REFERRER` = ?}, undef, $_t1->{USERNAM +E}); push(@row, Tr( td({-class=>"non_label_cell"}, Format_Date_For_Vie +wing($_t1->{d},"mysql_timestamp_view")), td({-class=>"non_label_cell"}, "$_t1->{USERNAME}") +, td({-class=>"non_label_cell"}, "$_t1->{FirstName} +$_t1->{LastName}"), td({-class=>"non_label_cell"}, "$_t1->{Phone}"), td({-class=>"non_label_cell"}, "$_state"), td({-class=>"non_label_cell"}, "$_num_referred") ) ); } $sth->finish(); $_page_content .= qq~ <script type="text/javascript" src="/css/js/sorttable.js"></sc +ript> ~ . table({-class=>"sortable", -id=>"toptbl", -border=>"1", -b +ordercolor=>"$vars{_table_border_color}"}, @row) . br(); } elsif ($_view && $_view eq "download") { my %states = Build_Hash("statecodes",""); my $sth = $dbh->prepare(qq{SELECT * FROM `member_records`}); $sth->execute(); my $_file2dl = qq~Date Registered,Username,Name,Phone,State,Re +ferrals\n~; while(my $_t1 = $sth->fetchrow_hashref()) { my $sth2 = $dbh->prepare(qq{SELECT * FROM `shipping_addres +s_records` WHERE `id` = ? AND `default` = ?}); $sth2->execute($_t1->{id},"1"); my $_s1 = $sth2->fetchrow_hashref(); $sth2->finish(); $_state = $_s1->{state}; $_state = $states{$_state}; if($_state && $_state =~ /Other /) { $_state = $_s1->{o_state} if $_s1->{o_state}; } $_num_referred = $dbh->selectrow_array(qq{SELECT COUNT(*) +FROM `member_records` WHERE `REFERRER` = ?}, undef, $_t1->{USERNAME}) +; $_file2dl = Format_Date_For_Viewing($_t1->{d},"mysql_times +tamp_view") . q~,~ . $_t1->{USERNAME} . q~,~ . "$_t1->{FirstName} $_t +1->{LastName}" . q~,~ . $_t1->{Phone} . q~,~ . $_state . q~,~ . $_num +_referred . "\n"; } $sth->finish(); my $type='text'; my $_format = 'text/csv'; my $file2 = "heavy_hitters.csv"; print header(-type => $_format, -Content_disposition => qq(att +achment; filename=$file2)); print $_file2dl; } else { $_page_content .= qq~ How do you want to view the file?<br> <br> ~ . a({-href=>"$_url/$in{pg}.html?load=$in{load}&view=view_her +e$inc_sess_id", -class=>"PageLink"}, qq~View Here in Sortable Table~) + . br() x 2 . a({-href=>"$_url/$in{pg}.html?load=$in{load}&view=download$inc +_sess_id", -onclick=>"alert('This may take a few minutes, so please b +e patient!\\nClick OK so it can work!');", -class=>"PageLink"}, qq~Do +wnload Comma Delimited file for Excel~) . br() x 2; } return 1; }
In reply to downloading csv file out of database by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |