
- Forum
- Programming Talk
- PHP
- Want to export and import data...
Want to export and import data...
This is a discussion on Want to export and import data... within the PHP forums, part of the Programming Talk category; In a fixed length format I would like to import and export data from Mysql using phpscript ....Please if anyone ...
-
Want to export and import data...
In a fixed length format I would like to import and export data from Mysql using phpscript ....Please if anyone knows let me know
Thanks in advance
-
it will be some thing like this...
You need to create a file then write the record to it ... if you need fixed lenght, you may need to pad each field with specific legnth you need.Code:$select = “SELECT * FROM MYNAME"; $export = mysql_query($select); $count = mysql_num_fields($export); Extract field names and write them to the $header variable for ($i = 0; $i < $count; $i++) { $header .= mysql_field_name($export, $i)."t"; } Extract all data, format it, and assign to the $data variable /**********/ while($row = mysql_fetch_row($export)) { $line = ‘’; foreach($row as $value) { if ((!isset($value)) OR ($value == “")) { $value = “t"; } else { $value = str_replace(’"‘, ‘""‘, $value); $value = ‘"‘ . $value . ‘"‘ . “t"; } $line .= $value; } $data .= trim($line)."n"; } $data = str_replace("r", “", $data); /************ /************/ if ($data == “") { $data = “n(0) Records Found!n"; } print “$headern$data";
Last edited by techguru; 10-11-2006 at 06:42 AM.

Reply With Quote





