How does php export data from a data table to an excel table?

Source: Internet
Author: User
Most of the time, the data in the database needs to be exported to excel. The following is the easiest way to export data without the need for an excel class. even if the function is simple, the project quot; has no complex requirements; quick effect quot ;. first define the header information to output an ex... most of the time, the data in the database needs to be exported to excel. The following is the simplest method. you do not need to export the excel class. even if the function is simple, the project with no complex requirements is "quick effect ".

Define the header information to output an excel file, and then echo the database information in the form of a table. the code is as follows:

 "; // Export the header (that is, the fields in the table) while ($ row = mysql_fetch_array ($ res) {$ t_field [] = $ row ['field']; // F in Field must be capitalized; otherwise, no echo is returned"". $ Row ['field']."";} Echo""; // Export 100 pieces of data $ SQL =" select * from users limit 100 "; $ res = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ res )) {echo""; Foreach ($ t_field as $ f_key) {echo"". $ Row [$ f_key]."";} Echo"";} Echo"";


Address:

Reprinted at will, but please attach the article address :-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.