netfrugal
01-29-2006, 05:59 PM
I've been able to export any data from MySQL to a csv file. But I've been having problems with stripping out all html code, and whenever there is a comma in the data, it sends all data to the next cell in excel. I included a str_replace function, but that is still not entirely working.
Let me show you what I've already done.
<?php if (!$HTTP_GET_VARS['submit']) { ?>
<?php
echo "Export and Save Customer Data onto your Local Machine";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export" name="submit"></form>';
?>
<?php
}
else
{
$contents="Board Category,Questions,Answers\n";
$user_query = mysql_query('select
f.faqdesk_id
, c.categories_id
, f.faqdesk_question
, c.categories_name
, f.faqdesk_answer_short
from faqdesk_description as f
join faqdesk_to_categories as f2c
on f.faqdesk_id = f2c.faqdesk_id
join faqdesk_categories_description as c
on f2c.categories_id = c.categories_id');
while($row = mysql_fetch_array($user_query))
{
$contents.=$row[categories_name].",";
$contents.=$row[faqdesk_question].",";
$answer = str_replace(',', '\,', $row[faqdesk_answer_short]); // escape internalt commas
$contents.=$answer."\n";
}
$contents = strip_tags($contents); // remove html and php tags etc.
Header("Content-Disposition: attachment; filename=export.csv");
print $contents;
?>
It stipped out html tags, but it is still leaving in
I'm sure there is a fix or replacement function for that. However, the commas are still giving separation problems, even with the str_replace function.
You can see the excel results here: www.mastertheboard.com/board_topic_export3.php
It is a list of questions and answers for the military soldiers in my units.
There is also some other formmating issues having to do with numbered bullets. But I'm not sure how that is fixed.
Any ideas?
Let me show you what I've already done.
<?php if (!$HTTP_GET_VARS['submit']) { ?>
<?php
echo "Export and Save Customer Data onto your Local Machine";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export" name="submit"></form>';
?>
<?php
}
else
{
$contents="Board Category,Questions,Answers\n";
$user_query = mysql_query('select
f.faqdesk_id
, c.categories_id
, f.faqdesk_question
, c.categories_name
, f.faqdesk_answer_short
from faqdesk_description as f
join faqdesk_to_categories as f2c
on f.faqdesk_id = f2c.faqdesk_id
join faqdesk_categories_description as c
on f2c.categories_id = c.categories_id');
while($row = mysql_fetch_array($user_query))
{
$contents.=$row[categories_name].",";
$contents.=$row[faqdesk_question].",";
$answer = str_replace(',', '\,', $row[faqdesk_answer_short]); // escape internalt commas
$contents.=$answer."\n";
}
$contents = strip_tags($contents); // remove html and php tags etc.
Header("Content-Disposition: attachment; filename=export.csv");
print $contents;
?>
It stipped out html tags, but it is still leaving in
I'm sure there is a fix or replacement function for that. However, the commas are still giving separation problems, even with the str_replace function.
You can see the excel results here: www.mastertheboard.com/board_topic_export3.php
It is a list of questions and answers for the military soldiers in my units.
There is also some other formmating issues having to do with numbered bullets. But I'm not sure how that is fixed.
Any ideas?