HIi, all of you........
I have site in which i have put a link to download a database table in a excel format.
visit this link and download
http://genat.com/anesthesia/index.php?option=com_content&view=article&id=54&Itemid=74
My script is working but when i download the file.
It displays the data in a single row
I want to display each record in a different row.
like this
- NAME PLACE CITY
- NAME PLACE CITY
- NAME PLACE CITY
anybody plz solve the problem. its urgent ..I reallly need the solution.
The code is :
<?php
$TableName = "city";
$select = "SELECT * FROM ".$TableName."
";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$csv_output .= mysql_field_name($export, $i) . "t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "t";
}
$line .= $value;
}
$data .= trim($line)."n";
}
$data = str_replace("r","",$data);
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=database_dump.csv");
header("Pragma: no-cache");
header("Expires: 0");
print $csv_output."n".$data;
exit;
?>
Thanks in advance