How to convert SQL to Excel in Php?
Many a times while developing a project we want to send the query data to the user or we want to have the query data for any other reason like analysis or report etc.
So to convert the SQL query data into the excel sheet form is many a times useful for developers.
You can do it using following code,
<? $sql = "select * from wp_db"; $result = mysql_query($sql); $arr_data = array(); while($data = mysql_fetch_assoc($result)){ $arr_data[] = $data;
}
$sep = "\t"; //tabbed character $fp = fopen('report.xls', "w"); $schema_insert = ""; $schema_insert_rows = ""; $schema_insert_rows.= "\t Query Result in Excel \n"; $schema_insert_rows.="Insert Headings here for each fields\t"; $schema_insert_rows.="\n"; fwrite($fp, $schema_insert_rows); foreach($arr_data as $k=>$v){ $schema_insert .= implode("\t",$v)."\n"; } fwrite($fp, $schema_insert); fclose($fp);
?>
save your file and run the code.
You will find one excel sheet saved in the same folder
as your file containing this code is residing.
You may like to read this also....
1 Comment to “How to convert SQL to Excel in Php?”
Post comment
Search in this website
our sponsors
latest comments
- sagar on List of all standard version of c language
- Mohit Dhukia on How to access/unblock songs.pk in india?
- shinto peter on How to configure mail from localhost ( wamp ) using PHP?
- tammylleanne on Implementation limitation of c programming language
- Deepak on How to access/unblock songs.pk in india?
Find us on Facebook
Top Authors
Find us on stackoverflow
Polls
Loading ...
My Bookmarks
- Audio/video Recorder & player application based on MATLAB
- check dependency of your binary
- defination of all standard c programming language function
- Great Question-Answer on c programming
- know what your c code means
- Limition of c programming language
- List of all version of c programming language
- Online c compiler
- php freelancing work
- some more stuff on C programming language
- Volatile Keyword in Embedded System
- Write Android application in c language
Thnx