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');