header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"yourfile.csv\"");
i am using this to produce a CSV file;
Currently it is displaying the data as;
Heading, Data, Heading 2, Data 2, Heading 3, Data 3…
i want to display the data as;
heading, heading 2, heading 3
data 1, data 2, data 3
How would this be done ?
<?php
$sql = "SELECT * FROM survey
WHERE id = '".sql_escape($s)."'";
$row = fetch0ne($sql);
if(!empty($row)) {
$int = array();
$sql = "SELECT * FROM survey_interests
WHERE survey = '".sql_escape($s)."'";
$interests = fetchAll($sql);
if(!empty($interests)) {
foreach($interests as $item) {
$int[] = getInterest($item['interest']);
}
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"yourfile.csv\"");
?>
Full Name, <?php echo $row['first_name']." ".$row['last_name']; ?>, Age, <?php echo $row['age']; ?>, Gender, <?php echo $row['gender'] == 'm' ? 'Male' : 'Female'; ?>, Country, <?php echo getCountry($row['country']); ?>, <?php if(!empty($int)) { ?><?php echo implode(", ",$int); ?><?php } ?>, Favorite colour, <?php echo getColour($row['colour']); ?>, Favorite search engine, <?php echo getSearchEngines($row['search_engine']); ?>
<?php
}
?>
you can change you code up: