Php exports data in the format of csvphp & nbsp; exports data. the format is csv & nbsp; no phpexcel class. Is there any other method? How should I write a class by myself? Thank you! ------ Solution ------------------ $ fp & nbsp; fopen (csv file name, & nbsp; w); $ rs & nbsp; mysql_query (php exports data in csv format)
Php exports data in csv format without using the phpexcel class. Is there any other method? How should I write a class by myself? Thank you!
------ Solution --------------------
$ Fp = fopen ('csv filename ', 'w ');
$ Rs = mysql_query ('select * from tbl_name ');
While ($ row = mysql_fetch_assoc ($ rs ){
Fputcsv ($ fp, $ row );
}
Fclose ($ fp );
------ Solution --------------------
If (isset ($ _ POST ['import']) {
$ File = $ _ FILES ['csv _ goods '];
$ File_type = substr (strstr ($ file ['name'], '.'), 1 );
// Check the file format
If ($ file_type! = 'Csv '){
Echo 'file format is incorrect. please upload it again! ';
Exit;
}
$ Handle = fopen ($ file ['tmp _ name'], "r ");
$ File_encoding = mb_detect_encoding ($ handle );
// Check the file encoding
If ($ file_encoding! = 'Ascii '){
Echo 'file encoding error. please upload it again! ';
Exit;
}
$ Row = 0;
While ($ data = fgetcsv ($ handle, 1000 ,',')){
// Echo "$ row"; // you can know the total number of rows.
$ Row ++;
If ($ row = 1)
Continue;
$ Num = count ($ data );
// The data of each cell in each row is output in sequence.
For ($ I = 0; $ I <$ num; $ I ++ ){
Echo $ data [$ I]."
";
// Process the data here
}
}
Fclose ($ handle );
}
?>