且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

导出excel文件

更新时间:2022-09-22 14:40:52

<?php
/**
* Created by PhpStorm.
* User: chenxiaolong
* Date: 2016/8/16
* Time: 14:37
*/
header("Content-type:application/vnd.ms-excel;charset=utf-8");
header("Content-Disposition:attachment;filename=Export_top_100.xls");
$tab="\t"; $br="\n";
$head= 'rank' . $tab . "skinid". $tab . 'title' .$tab . 'num' . $tab . 'skinurl' . $br;
echo $head;
$db = array (
   'database' => '360se_skin', // 库名称
   'host' => '220.181.158.172', // 数据库地址
   'port' => 3306, // 端口
   'login' => '360se_skin', // 用户名
   'password' => '360se_skin@browser', // 密码
   'persistent' => false, // 是否使用长链接
   'charset' => 'utf8',
);
$mysqli = new mysqli($db['host'],$db['login'],$db['password'],$db['database'],$db['port']);
$mysqli->query("set names utf8");
$sql = "select * from skins where deleted=0 order by num desc limit 101";
$query = $mysqli->query($sql);
$i = 1;
while($res=$query->fetch_assoc()) {
   echo $i . $tab;
   echo $res['skinid'] . $tab;
   echo $res['skinname'] . $tab;
   echo $res['num'] . $tab;
   echo $res['skinurl'];
   echo $br;
   $i++;

}

本文转自 陈小龙哈 51CTO博客,原文链接:
http://blog.51cto.com/chenxiaolong/1839292