I am using this code to generate csv files from a mysql db.
I don t how how to do for export csv's with maxim 500 rows. For example if i found 1100 results on query i want to have as result 3 csv files, 1 two with 500 lines and third one with 100 lines.
<?php
include "connection.php";
$filename = 'export.csv';
$fp = fopen($filename, "w");
$res = mysql_query("SELECT id, name, first_name, middle_name, last_name, phone FROM data WHERE active='1' ");
$row = mysql_fetch_assoc($res);
$line = "";
$comma = "";
foreach($row as $name => $value) {
$line .= $comma . '"' . str_replace('"', '""', $name) . '"';
$comma = ",";
}
$line .= "
";
fputs($fp, $line);
mysql_data_seek($res, 0);
while($row = mysql_fetch_assoc($res)) {
$line = "";
$comma = "";
foreach($row as $value) {
$line .= $comma . '"' . str_replace('"', '""', $value) . '"';
$comma = ",";
}
$line .= "
";
fputs($fp, $line);
}
fclose($fp);
?>
Thank you