I built a function in the back office for the administrators that will show them a list of the members in the database. The problem is not the pull out of the database, nor that it pulls from 3 different tables, it is that there are thousands of members, and it does not ever download. I get the box to save, open or whatever else have you, but then if I click Open, it never opens. If I click Save, I never got the box to have me put it somewhere.

I will put the part of my code I am doing this from, can you tell me what I did wrong?
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; }
I would appreciate any help you can be.

thank you.
Richard

In reply to downloading csv file out of database by Anonymous Monk

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.