PHP Help - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP Help (/showthread.php?tid=95620)
PHP Help by ipab on 10-19-2010 at 12:47 AM
So I'm in the final stages of finishing my project, and I am stumped on something. I figured there are enough PHP genii around here to give me a hand with this.
I am trying to output data from a table called data in mysql, to a tab delimited, text file. My problem is that the new line isn't being reflected. The tabs are, but no new lines
code: $q = "SHOW COLUMNS FROM ".TBL_DATA."";
$result = $database->query($q);
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."\t";
$i++;
}
}
$csv_output .= "\n";
$q2= "SELECT * FROM ".TBL_DATA." WHERE ListID = '$listingsort'";
$values = $database->query($q2);
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."\t";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/octet-stream");
header("Content-disposition: attachment" . date("Y-m-d") . ".txt");
header( "Content-disposition: filename=".$filename.".txt");
echo $csv_output;
I've tried everything I could think of/googling. I have no idea what is going wrong and any help would be much appreciated
RE: PHP Help by Mnjul on 10-19-2010 at 12:56 AM
Use \r\n instead of \n only if you want to open the file on Windows.
RE: PHP Help by ipab on 10-19-2010 at 12:59 AM
Damn... That would make a lot of sense
The simplest thing really. Thank you very much. I was going crazy with this.
|