473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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:
good,
very good!
ok!


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">
  3. <TEXTAREA NAME="Comment" ROWS=18 COLS=50></TEXTAREA>
  4.  
  5. "survey table in mysql"
  6. Field           Type       Null     Key   Default   Extra
  7. id                char(2)    YES            NULL
  8. comment     text         YES            NULL
  9.  
  10. "survey_result.php"
  11. $query = "insert into bar values
  12. ('".$id."','".$comment."')";
  13.  
  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']);
  18.  
  19. "survey.txt"
  20. ID              Comment
  21. 15             good,
  22. very good!
  23. ok!
  24.  
Mar 13 '08 #1
1 1920
ronverdonk
4,258 Expert 4TB
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.

MODERATOR
Mar 15 '08 #2

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

Similar topics

5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
0
by: JohnLH | last post by:
Hi, I am having an issue with the LOAD DATA LOCAL FILE command on the latest 3.0.9 JDBC Driver. The command works on Windows, but doesn't seem to work on OSX and Linux. The error that I get on...
2
by: Brett B | last post by:
I just installed mysql on linux. If I open a terminal, su to root, then type "mysql", I am able to connect to the server and run my queries. If I exit out of su so that I am my own id (baisley)...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
3
by: ravikiranveluguleti | last post by:
hi, this is ravikiran i am working on a project(using java & mysql) that requires creation of a editable mysql file that contains all the data present in a particular table ,(like .mdb file that...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
0
by: ansuhua | last post by:
Hi, I want to build a file structure to store information in binary format. Can mysql file structure be used for reference? How is the mysql file structure? What is .MYD format? Thanks
0
ADezii
by: ADezii | last post by:
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a...
6
by: Dave067 | last post by:
Hi This is my first attempt at writing Python script - it's probably a bit ambitious, but there again, whatever doesn't kill you makes you stronger... ;-) I'm trying to write a script for a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.