I am using the following code:
Code: Select all
function threads_csv()
{
db_connect();
$result = mysql_query("Select * from hrd order by thread_date DESC");
while($row = mysql_fetch_array($result))
{
$thread_id = $row['thread_id'];
$parent_id = $row['parent_id'];
$order = $row['thread_order'];
$title = $row['thread_title'];
$body = strip_tags($row['thread_body']);
$body = stripslashes($body);
$user = $row['thread_user'];
$date = $row['thread_date'];
$data .= "$thread_id, $parent_id, $order, $title, $user, $date, $body\n";
}
$filename = "training_journal_threads.csv";
header ('Content-type: text/csv');
header ('Content-Disposition: attachment; filename='.$filename);
print "Thread ID, Parent Thread, Order, Title,User, Date, Body\n";
echo $data;
exit();the csv is created. But due to the amount of text in the body variable the body field is all over the csv file and messes up how the columsn are structured. I have stripped tags and slahes but this has not fixed the problem.
Is there a certain thing that needs to be done to fix this?
All suggestions welcome.
Thanks in advance