class Export_csv{
public function get(){
$str = "项目描述,项目痛点,资源投入,项目关键词,项目收益,团队成员,投入钱财,运营时间,姓名,职位/区域,邮件,手机\n";
$str = iconv('utf-8','gb2312',$str);
$CSVInfo = $this->getCSVInfo();
for($i=0;$i
$title = iconv('utf-8','gb2312',$CSVInfo[$i]['title']);
$des = iconv('utf-8','gb2312',$CSVInfo[$i]['des']);
$ques = iconv('utf-8','gb2312',$CSVInfo[$i]['ques']);
$invest = iconv('utf-8','gb2312',$CSVInfo[$i]['invest']);
$keyword = iconv('utf-8','gb2312',$CSVInfo[$i]['keyword']);
$reward = iconv('utf-8','gb2312',$CSVInfo[$i]['reward']);
$member = iconv('utf-8','gb2312',$CSVInfo[$i]['member']);
$need = iconv('utf-8','gb2312',$CSVInfo[$i]['need']);
$money = iconv('utf-8','gb2312',$CSVInfo[$i]['money']);
$time = iconv('utf-8','gb2312',$CSVInfo[$i]['time']);
$username = iconv('utf-8','gb2312',$CSVInfo[$i]['username']);
$place = iconv('utf-8','gb2312',$CSVInfo[$i]['place']);
$email = iconv('utf-8','gb2312',$CSVInfo[$i]['email']);
$phone = iconv('utf-8','gb2312',$CSVInfo[$i]['phone']);
$str .= $title.",".$des.",".$ques.",".$invest.",".$keyword.",".$reward.",".$member.",".$need.",".$money.",".$time.",".$username.",".$place.",".$email.",".$phone.","."\n";
}
$filename = date('Ymd').'.csv';
$this->out_csv($filename,$str);
}
public function out_csv($filename,$data){
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $data;
}
private function getCSVInfo(){
return MySQL::getInstance()->query('select * from ck_plan')->fetchAll(PDO::FETCH_ASSOC);
}
}
如图所示,字段本应该csv一行列出所有字段数据,但是数据跑到第二行或者第三行去了