lilywong Posted July 27, 2006 Share Posted July 27, 2006 Any idea of exporting a mysql data to a textfile, saved it as file.txt ? Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/ Share on other sites More sharing options...
Branden Wagner Posted July 27, 2006 Share Posted July 27, 2006 how much data? and whats its purpose? just exporting the results to a text file, or the actual table itself, as in a back up? Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/#findComment-64483 Share on other sites More sharing options...
effigy Posted July 27, 2006 Share Posted July 27, 2006 Look at mysqldump. Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/#findComment-64484 Share on other sites More sharing options...
lilywong Posted July 31, 2006 Author Share Posted July 31, 2006 just want to export some data, possibly 100 records from database, and save in abc.txt, that's it. not for backup, is for a report. like CSV file. Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/#findComment-66181 Share on other sites More sharing options...
lilywong Posted July 31, 2006 Author Share Posted July 31, 2006 i found a solution of this, but the data output is all in one line, i have use the "\n", but everything still printed out in one line, just wondering, i wanna the record to be printed out in many lines based on different ID.for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "|";}while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "|"; } else { //$value = str_replace('|', '', $value); $value = "|".$value."|"; } $line .= $value; } //$data .= trim($line). "\n"; $data .= $line."\n";}//$data = str_replace("\r","",$data);if ($data == "") { $data = "\n(0) Records Found!\n";}header("Content-type: application/x-msdownload");header("Content-Disposition: attachment; filename=extraction.txt");header("Pragma: no-cache");header("Expires: 0");print "$header\n$data"; Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/#findComment-66185 Share on other sites More sharing options...
Drumminxx Posted July 31, 2006 Share Posted July 31, 2006 if you just want a simple text file, you could just loop through the records you want and build a string formatted the way you want and then the code below is an example of how to create the actual text file[code] $fh = fopen('FILE_PATH', 'w') or die("ERROR: can't open file for writing"); fwrite($fh, $NEW_FORMATTED_STRING); fclose($fh);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15774-export-data-to-textfile/#findComment-66187 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.