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;
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.