Php Export Excel File
Export Data to Excel in PHP MySQL. Export data functionality is very useful where someone has to save data from the web application to his personal computer for future use.So today in this tutorial we will learn how we can Export Data to Excel inu PHP and MySQL.
Hello everyone. Today in this article, I will explain to you about exporting the reports in Excel format using PHP and MySQL. So, I will create one simple PHP page that will display data from the My SQL database in tabular format and then we put one button. By clicking this button, we can export the Excel file which is automatically downloaded to your machine. • Make Table in My SQL for storing the user.
Give it the name “tbl_User”. This table contains UserName, Password etc. For creating a table, run the below script. Download Nada Dering Mp3 Untuk Hp. Hotel Booking Php Software For Free.
• CREATE TABLE IF NOT EXISTS `tbl_user` ( • `ur_Id` int (11) NOT NULL AUTO_INCREMENT, • `ur_username` varchar (50) NOT NULL, • `ur_password` varchar (50) NOT NULL, • `ur_status` int (11) NOT NULL, • PRIMARY KEY (`ur_Id`) • ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; By running the above script, it will create a table like below. Here, table contains Id, Username, Password, Status etc columns • Now, insert some temporary data to this table. So, for inserting data in the temporary table, I run the below SQL script.
• $columnHeader = '; • $columnHeader = 'Sr NO'. ' t'; • Here, when user clicks on link, we have to download the excel file directly, without showing the data. Just add the below code.
Header('Content-type: application/octet-stream'); • Now, we have to set the filename for downloading excel file. Header('Content-Disposition: attachment; filename=User_Detail_Reoprt.xls'); header('Pragma: no-cache'); header('Expires: 0'); • Now, finally we print all the table row data and header data to the excel file.