CSV文件中的空格

I am using php to export data from Database.My problem is.Data export successfully but it create two blank rows at beginning.I want to remove them.Here is my code

if($_POST){
$output = "";
$table = "schedule"; // Enter Your Table Name 
$sql = mysql_query("select * from $table WHERE post_id='".$_POST['schedule_id']."'");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="
";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.trim($row["$i"]).'",';
}
$output .="
";
}
$filename = "schedule.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;
exit;
}

You should wrap string with spaces with double quotes or any other character.

See the function provided by this answer https://stackoverflow.com/a/3933816/1163444