/    Sign up×
Community /Pin to ProfileBookmark

export to csv

I have a page that displays data from a db2 database. I then have a button to export the data to a text file (csv). My display page works fine, no matter how many rows of data I have. It seems that if I have more than 2000 rows, then the browser displays my csv.php page, with no content. If there are less than 2000 rows, then I get the dialog box to save my file. Below is the code for my csv.php file. Any help would be greatly appreciated.

[code]
<?
//header(‘Content-Type: text/x-csv;’);
header(‘Content-Type: application/octet-stream;’);
header(“Content-Disposition: attachment; filename=fav_rx.txt”);

include “db2conn.php”;
include “config.php”;
include “sitecommon.php”;

$begin_dte = $_POST[‘begin_dte’];
$end_dte = $_POST[‘end_dte’];

$D = new mydb2;
$sql = ” SELECT
INCNE_ENTRY_FNAME, INCNE_ENTRY_LNAME, INCNE_ENTRY_ADDR1, INCNE_ENTRY_ADDR2, INCNE_ENTRY_CTY, INCNE_ENTRY_ST, INCNE_ENTRY_ZIP, INCNE_ENTRY_PHN1, INCNE_ENTRY_PHN2, INCNE_ENTRY_DOB, INCNE_ENTRY_EMAIL, INCNE_ENTRY_RPHNAME, INCNE_CONT_FIELD1, INCNE_CONT_FIELD2, INCNE_CONT_FIELD3, INCNE_CONT_FIELD4, INCNE_CONT_FIELD4, INCNE_COMMENT, INCNE_REQ_IND, INCNE_LST_MNT_TSMP FROM INET.INCNE_CONTEST_ENTRY WHERE INCNE_CONTEST_NBR = 1 and INCNE_LST_MNT_TSMP >= ‘” . $begin_dte . “‘ and INCNE_LST_MNT_TSMP <= ‘” . $end_dte . “‘”;

$order = ” ORDER BY INCNE_ROW_ID “;
$sql = $sql .$order;
$D->my_sel($sql);
//print $sql;

if ($D->ORA_ERR) {
echo “<font color=red>db2 error ->”
.$D->ORA_ERR_DESC
.”<-</font>>”;
}

if ($D->numrows != 0) {
echo (“First NametLast NametAddress1tAddress2tCitytSttZiptPhone NumbertEmailtBirthdatetPharmacist NametStore AddresstStore CitytStore StatetStore ZiptCommentstOfferstLast Update Timestamprn”);

for ($i=0; $i< $D->numrows; $i++) {

//$entry_date=$D->results[“INCNE_LST_MNT_TSMP”][$i];
$first_nme=$D->results[“INCNE_ENTRY_FNAME”][$i];
$last_nme=$D->results[“INCNE_ENTRY_LNAME”][$i];
$addr1=$D->results[“INCNE_ENTRY_ADDR1”][$i];
$addr2=$D->results[“INCNE_ENTRY_ADDR2”][$i];
$city=$D->results[“INCNE_ENTRY_CTY”][$i];
$st=$D->results[“INCNE_ENTRY_ST”][$i];
$zip=$D->results[“INCNE_ENTRY_ZIP”][$i];
$phn_nbr=$D->results[“INCNE_ENTRY_PHN1”][$i];
$birthdate=$D->results[“INCNE_ENTRY_DOB”][$i];
$email=$D->results[“INCNE_ENTRY_EMAIL”][$i];
$pharmacist_nme=$D->results[“INCNE_ENTRY_RPHNAME”][$i];
$store_address=$D->results[“INCNE_CONT_FIELD1”][$i];
$store_city=$D->results[“INCNE_CONT_FIELD2”][$i];
$store_st=$D->results[“INCNE_CONT_FIELD3”][$i];
$store_zip=$D->results[“INCNE_CONT_FIELD4”][$i];
//$store_number=$D->results[“INCNE_CONT_FIELD4”][$i];
$comments=$D->results[“INCNE_COMMENT”][$i];
$comments = str_replace(“r”, ”, $comments);
$comments = preg_replace(‘/(?<!>)n/’, ” “, $comments);
$offers=$D->results[“INCNE_REQ_IND”][$i];
$lastUpdateTimestamp=$D->results[“INCNE_LST_MNT_TSMP”][$i];

//$position = strpos($comments, “r”);

echo (“$first_nmet$last_nmet$addr1t$addr2t$cityt$stt$zipt$phn_nbrt$emailt$birthdatet$pharmacist_nmet$store_addresst$store_cityt$store_stt$store_zipt$commentst$offerst$lastUpdateTimestamp”);

echo (“rn”);
}
}
//echo “anb”;
?>
[/code]

Thanks

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...