By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

How can I format-output data from Mysql to a file?-relatively long

P: 17
I am new in PHP/Mysql. I want to input sth from website to mysql, then output the formatted data to .txt, and finally use Excel to open the .txt file. I believe there are better and simpler ways than what I did. But I want to know what's wrong in my codes. Here are the details:
In survey.html, I need people input their ID and comment.
In Mysql, I've already made the survey table.
I use survey_result.php to import people's input to that table in Mysql.
Then I use survey_file.php to get data in Mysql into a survey.txt file.
Later I use Excel to open this .txt file.

My problem is, if more than one paragraph entered in "comment" field in survey.html, like:
very good!

the last two paragraphs appeared in the first column (ID) in the survey.txt file.
But what I expect is they be in the 2nd (i.e., comment) column; and when I use Excel to open the .txt file, all these three paragraphs should be in one cell in the comment column.

Below are the key codes/descriptions:
Expand|Select|Wrap|Line Numbers
  1. "survey.html"
  2. <input type="text" size="30" name="ID">
  5. "survey table in mysql"
  6. Field           Type       Null     Key   Default   Extra
  7. id                char(2)    YES            NULL
  8. comment     text         YES            NULL
  10. "survey_result.php"
  11. $query = "insert into bar values
  12. ('".$id."','".$comment."')";
  14. "survey_file.php"
  15. $fp = fopen("survey.txt", 'wb');
  16. $row = $result->fetch_assoc();      
  17. fprintf ($fp, "%s\t%s\n",$row['id'], $row['comment']);
  19. "survey.txt"
  20. ID              Comment
  21. 15             good,
  22. very good!
  23. ok!
Mar 13 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,258
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Mar 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.