01-15-2008, 09:08 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Posts: 41
Thanks: 24
|
exporting data to csv
currently i have a script that exports to csv file from mysql but it seems as there are more rows of data, the script kind of stops working...
current i'm using this function:
PHP Code:
function generatecsv($start, $end){
$delim = ",";
$query = "SELECT * FROM users WHERE userid >= '$start' AND userid <= '$end'";
$d = db();
$result = mysql_query($query, $d);
mysql_close($d);
$csv_output = "userid,email,firstname,lastname";
$csv_output .= "\n";
while($row = mysql_fetch_array($result)) {
$uid = $row['userid'];
$em = $row['username'];
$fn = $row['firstname'];
$ln = $row['lastname'];
$csv_output .= $uid . $delim;
$csv_output .= $em . $delim;
$csv_output .= $fn . $delim;
$csv_output .= $ln . $delim;
$csv_output .= "\n";
}
header("Content-Type: application/force-download\n");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Content-Disposition: attachment; filename=data_" . date("dmY") . ".csv");
print $csv_output;
exit;
}
is there a better way of doing this when there's like 50,000 rows of data?
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
|
|
|
|