$value) { $line .= $comma . '"' . str_replace('"', '""', $name) . '"'; $comma = ","; } $line .= "\n"; fputs($fp, $line); // remove the result pointer back to the start mysql_data_seek($res, 0); // and loop through the actual data while($row = mysql_fetch_assoc($res)) { $line = ""; $comma = ""; foreach($row as $value) { $line .= $comma . '"' . str_replace('"', '""', $value) . '"'; $comma = ","; } $line .= "\n"; fputs($fp, $line); } $pageno = $pageno+1; //count page number for next file generation } fclose($fp); ?>