Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display indents and paragraphs within MySql db

Status
Not open for further replies.

HowdeeDoodee

Technical User
Mar 14, 2005
61
US
I want to display an outline with indentations and with paragraphs below some of the outline headings. I have the file set up in Word and can convert to Excel and then to a csv file to be transfered into MySql. Paragraph marks in a csv file indicate a new record which I do not want. I want indentations and paragraphs to appeear from within each record if necessary.

How do I make indentations and separate paragraphs appear on a PHP paginated results page when the results page data only comes from MySql retrieved data? Is there a way to make this happen in the csv file?
 
i assume that you mean that you want the indents etc to appear when outputted to a web page? (i.e. not when the raw data is examined in the csv or db).

why not include the new line and carriage return codes (\r\n) for the line endings and \t for each tab. then when you display the output, put it between <pre> tags?
 
jpadie --- Thank you very much for the response. I am beginning to see some daylight except for the <pre> tags. The results appear in table format generated from pagination code. Where and how can I put the <pre> tags? Can I put the <pre> tags at the bottom and top of the php page containing the pagination code or do the tags have to be integrated into the pagination code itself?
 
good question. and i *think* the answer depends on what doctype you use.

for sure it will work with old doctypes and new if you include the <pre> tags in each table cell (i.e. inside the <td> tags).
 
Well, I've tried inserting the \t and \r but they printed out instead of inserting a tab or carriage return. When that did not work I tried to insert tabs and soft carriage returns directly but that did not work either. I inserted the <pre> and </pre> tags in the part of the code where the table is printed out in the pagination code. Any suggestions?
 
i guess you are using a unix box?

can you provide some text that you would want to enter into the db and have shown formatted on the screen?
 
jpadie, thank you for the reply. Your help is really appreciated. Please keep in mind I am a novice.

Here is the way the text is set up in my word processor and here is the way I want the text to be displayed when a user retrieves this record from the MySql database. All of the following lines would be stored in one record. When I pasted my reponse into the board software I placed the word "tab" enclosed in brackets [ and ]. When I went to display the example, the outline appears perfectly. Can you use the "tab" marker with the brackets in setting up a database record to get the record to display tabs and indents? I had to include the "tab" markers to get the outline format to display. Like my application, php board software will not recognize tabs inserted from my keybaord.

I believe my problem can be solved by using the nl2br(preg_replace() function but I do not know what to use as a replacement for the tabs in my MS Word file. I think maybe the \t and \r can be used with this nl2br (preg_replace() function but I do not know how to use the function or where to put the function in the php code. To make the equivalent of a tab like is shown this outline below, what do you use as a replacement for the tab character I would normally use in MSWord? To make the equivalent of a paragraph mark in MSWord, what do you use as a replacement? Since I am inserting my MSWord pages into excel, then saving as a comma or tab delimited file, then copying that file into my database using phpMyAdmin, do I use the \t and \r in MS Word, in Excel, and then in the text file pasted into phpMyAdmin and then replace the \t and \r before display?

Here is what I want the user to see when the user pulls up one record from the db.

I. Topic Heading
[tab][tab]A. Subtopic Heading
[tab][tab][tab]1. Subsubtopice Heading
[tab][tab][tab][tab]a. Subsubsubtopic Heading
[tab][tab][tab][tab]b. Subsubsubtopic Heading
[tab][tab][tab][tab][tab]Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. [tab][tab][tab][tab][tab]Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. [tab][tab][tab][tab][tab]Paragraph of text goes here.
[tab][tab][tab][tab]c. Subsubsubtopic Heading
[tab][tab]2. SubsubtopicHeading
[tab][tab][tab][tab]a. Subsubsubtopic Heading
[tab][tab][tab][tab]b. Subsubsubtopic Heading
[tab][tab][tab][tab]c. Subsubsubtopic Heading
2. Topic Heading
Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here.
[tab][tab]A. Subtopic Heading
[tab][tab][tab]1. Subsubtopice Heading
[tab][tab][tab][tab]a. Subsubsubtopic Heading
[tab][tab][tab][tab]b. Subsubsubtopic Heading
[tab][tab][tab][tab]c. Subsubsubtopic Heading
[tab][tab]2. SubsubtopicHeading
[tab][tab][tab][tab]a. Subsubsubtopic Heading
[tab][tab][tab][tab]b. Subsubsubtopic Heading
[tab][tab][tab][tab]c. Subsubsubtopic Heading
 
i will take a look.

in the meantime a thought and a question:

thought: ms word can save as an html file. does this solve your problem? you could then just shove the file contents into your db. you could even automate the process.

question: im still unclear as to the format of the data that you are putting into your database. could you post the string output that you are storing (i.e. what goes into your insert statement?)

 
jpadie, thank you for the reply.

I am using phpMyAdmin to input or insert records into my database. I copy and paste into the insert pane. When I copied and pasted the above outline here is what the insert statement looked like. All tabs that were in the outline that made the outline look like an outline were not preserved in the sql statement.

SQL-query:
INSERT INTO `Table100` ( `Topic` , `Subtopic` , `References` )
VALUES (
'DDD', 'I. Topic Heading A. Subtopic Heading 1. Subsubtopice Heading a. Subsubsubtopic Heading b. Subsubsubtopic Heading Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. c. Subsubsubtopic Heading 2. SubsubtopicHeading a. Subsubsubtopic Heading b. Subsubsubtopic Heading c. Subsubsubtopic Heading 2. Topic Heading Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. Paragraph of text goes here. A. Subtopic Heading 1. Subsubtopice Heading a. Subsubsubtopic Heading b. Subsubsubtopic Heading c. Subsubsubtopic Heading 2. SubsubtopicHeading a. Subsubsubtopic Heading b. Subsubsubtopic Heading c. Subsubsubtopic Heading ', 'None'
);

Normally I create a csv file by saving a file in excel to csv format and then paste the csv file contents into the insert pane of phpMyAdmin. In the above insert there are three fields. The three fields are Topic, Subtopic, and References.
 
in your input you have no formatting information. you're not picking it up with a cut and paste. if you have no formatting in your input then there is very little you can do in the output without parsing and changing it.

if there is a way to distinguish between different sections of your string then you could insert span tags with a given indent.

alternatively, could you not just save your word files as html and use them natively?

 
jpadie, thanks. I cannot store the data in plain html files because the number of files would be too prohibitive. Currently there are nearly a million records so storing each record in a separate html file would not do. Storing groups of records in html does not work either because storing groups of records in one html negates the ability of the user to only pull up matching words and phrases.

In the csv file, sections of the string are determined by commas since the csv file is comma delimited.

Could you give me an example of how I can format the data in a csv file?

You also said "...you could then just shove the file (html)contents into your db. you could even automate the process." Could you please explain how I can transfer an html file into a MySql database by using phpMyAdmin?
 
two questions:
1. the csv file
2. automating the process.

i'll answer 1 if you can either describe the format of the csv file or mail me a sample (justin DOT adie AT m-legal DOT net)

the 2nd is more in depth. in pseudo code you'd do the following:

1. create com word object
2. open word file
3. save word file as html file
4. close files.
5. open html file in php using fopen
6. suck in all the contents of the file
7. discard the contents you don't want (ie all the office header muck)
8. bung the remaining contents into a db using PHP (NOT PHPMYADMIN).
Code:
// user set variables
$hostname = "";
$user = "";
$password="";
$databasename="";
$table="";
// end var set

//nb $contents is the result of the html cleanup
mysql_pconnect($hostname, $user,$password)
 or die("unable to connect to db server. ".mysql_error());
mysql_select_db($databasename)
 or die (unable to connect to database. ".mysql_error());
$sql = "insert into $table 
       set contents = '"
       .mysql_real_escape_string($contents)."'";
mysql_query($sql);

in office the tabs are converted to style declarations when saved as html files. internet explorer reads this natively. not sure about other browsers
Code:
<span style='mso-tab-count:2'></span>
if you have problems, you would then run all of this through a str_replace to replace the string with a classname and then set the indent in css.

but ... i have to ask ... why are you going through all this at all? does you office suddenly have a requirement to make all its word documents viewable as html or just viewable on the web? is this to make searching easier? I can't help thinking that the fundamental approach appears flawed but this is definitely a pre-judgement as i don't know WHY you want to do this. Perhaps we could help more or be more creative if you were to give us an explanation?

i'll post back on the csv when i get your sample file.
Justin
 
Problem Solved. I did not know you could insert html tags directly into a csv file uploaded or pasted into phpMyAdmin. Since YOU CAN insert html tags into a csv file for upload, I inserted the html for carriage returns and tabs to get the indentation I wanted. Subsequently, I will not be able to do a mass search and replace on all word files, inserting the html components as needed.

To jpadie, I wish to express my gratitude for the help provided. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top