php mysql export csv excel format and save

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags csv data default download export file mysql mysql database

php tutorial mysql tutorial Export csv excel format file and save This is a paragraph I used in my own time to use a php export mysql database tutorial save the data into a csv file and provide download, the principle is very simple to mysql data found out, Then save it to a .csv file in csv format so that's ok.
* /

$ times = time ();
$ filename = $ times. ". csv";
$ a = "contact, contact number, application time n";

$ days = postget ("days");

$ mktime = daystomktime ($ days);
$ sql = "select * from v_tugou where ($ times-times) <$ mktime";
$ db = new db ();
$ result = $ db-> query ($ sql);
$ rs = $ db-> fetch ($ result, 0);
foreach ($ rs as $ v => $ vv)
{
$ a. = $ vv ['name']. ','. $ vv ['mo']. ",";
$ a. = date ('ymd', $ vv ['times']). "rn";
}
// echo $ a;
$ hod = fopen ($ filename, "w +");
if (fwrite ($ hod, $ a))
{
Echo "generate excel file success, click <a href=$filename target=_blank> right click save as excel document </a>";
}

/ *
data structure
-
- The structure of the table `hn_tugou`
-

create table if not exists `v_tugou` (
`id` int (4) not null auto_increment,
`name` varchar (20) not null default '0',
`mo` varchar (20) not null default '0',
`times` int (4) default null,
`ip` varchar (20) not null default '0',
primary key (`id`)
) engine = myisam default charset = utf8 auto_increment = 2;

-
- Export the data in the table `hn_tugou`
-

insert into `hn_tugou` (` id`, `name`,` mo`, `times`,` ip`) values
(1, 'adsense', 'www.111cn.net', 1283241159, '192.168.0.119');

Related Article

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.