使用以下代码用户从数据库下载信息(以csv格式)。但是获取输出的行很多都是空白的,即在我的csv中会有两行。但是在第一行第2行之后获取csv将被打印出来。
public generatecsvAction()
{
$answermodel=new Model_DbTable_Answers();
header("Content-type: application/octet-stream");
//header('Content-Type: text/csv; charset=utf-8'); // tried this too but still same output
header("Content-Disposition: attachment; filename=exportevent.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo "First_Name,Last_Name,Roll_No1,User_name,col1,col2,col3..... \n"; // checked without this \n
foreach($testarray as $i)
{
$ans = $answermodel->getanswers1($a,$i);
if(count($ans)==10) // if user answered all the qustions ,
{
//echo "1,";
foreach($ans as $value)
{
$res=$answermsamodel->findansweroption($value);
$res=$res.",";
$s=$s.$res;
}
echo $s;
break;
}
}
}
答案 0 :(得分:0)
最有可能的是,$answermsamodel->findansweroption($value)
会返回包含换行符的值。