Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Formatting of text retrieved from database
Reply

 

Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
futurejp is on a distinguished road
 
Posts: 10
Join Date: Jun 2008
Default Formatting of text retrieved from database - 07-16-2008, 03:19 AM

Hey.

I have a little form on a website where a person enters his/her name in one box, posts text in the second, and presses submit. Then the page refreshes, this data is entered into a table in my database, and then the data is retrieved back and posted on the page. Here's the problem.

Say the text the person entered in is:


"Hi! I know these composers:

Bach
Mozart

and these bands:

The Rolling Stones
Phish"


This text is inserted into my table this way, but when I retrieve it and post it, all text formatting is gone. So it looks like:

"Hi! I know these composers:Bach Mozart and these bands: The Rolling Stones Phish"

Or something like that. Essentially, extra spaces, line breaks, and things like that aren't kept. How can I fix this? Is it just as simple as changing the Field Type in my table? Right now, the type is just 'TEXT.' Or if not, what can I do?

Thanks
Reply With Quote
(#2 (permalink))
Old
Junior Member
futurejp is on a distinguished road
 
Posts: 10
Join Date: Jun 2008
Default 07-16-2008, 04:02 AM

Actually, solved it myself. Just put the retrieved text in <pre></pre> tags, and set the font of that stuff to match the rest of my page. Thanks anyway
Reply With Quote
(#3 (permalink))
Old
Junior Member
futurejp is on a distinguished road
 
Posts: 10
Join Date: Jun 2008
Default 07-17-2008, 02:33 AM

Actually, I still have a problem, and I'm wondering if anybody could help. Take a look at this page of my website, it has an example of this form:
http://vindaloo.web44.net/tour.php?d...84&t=2&tour=23

If you post a review or comments, the page will refresh and you'll see them. Here's my question.

The main contents of that page, namely the Date, Location, Venue, Support, Setlist, Notes, and Reviews section are all in a 2-column table. The table width is 700px, I think. I set the width of the left column to be 14% of the total. For the couple elements in left columns that are wider (such as the light-blue "----------------------------------" that you'll see) I tell it that colspan=2. Fine, it works.

And, per my above posts, now if you post a review and use line breaks and things like that, they will stay there. But here's the problem. If you DON'T use line breaks, and you type a lot, your whole comment will just stay on one line, and for some reason, it will dramatically increase the width of my table. For example, if you typed this as a review:

"Words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words " etc, then it won't recognize a table boundary and cut to a new line. Rather, the table extends itself to the right, therefore also increasing the width of the left-column (because it's just 14% of whatever the total width is) and just giving the page a horizontal scrollbar which I hate.

How can I make it so that when the contents of a review reach the end of the 700px table, it essentially uses 'word wrap'? You can see in the Notes: section on that same page that this happens there. The text "these notes are for debugging" were all printed on one line, and when it reaches the end of the table, it wraps around.

Any ideas?

Thanks
Reply With Quote
(#4 (permalink))
Old
Junior Member
Tarman is on a distinguished road
 
Posts: 6
Join Date: Jul 2008
Default 07-18-2008, 01:41 PM

I beleive I got a good work around for it but not sure it is what you will want to do. You must put a table within a table. Set the outside table to a fixed length VIA Pixels not %. Then on your internal table leave the length blank and the internal table will adjust to the correct text size without pushing out past your other table. This will allow all your inner parts of the table to auto adjust and it will word wrap if need be.

If they ever stop reveiwing my website for approprate data you can see what I am talking about by going here. http://ddoitems.net63.net/

If you need to see the coding I can post it later for you I just need to head off to my real life job...LOL
Reply With Quote
(#5 (permalink))
Old
Mr.Whisper's Avatar
Member
Mr.Whisper is on a distinguished road
 
Posts: 34
Join Date: May 2008
Send a message via MSN to Mr.Whisper
Default 07-19-2008, 02:23 PM

php has a function for this problem

just use nl2br($string);

this will replace new line with <br>


WhisperForum

We present Freeware & Opensource to Everyone!
Reply With Quote
(#6 (permalink))
Old
Junior Member
futurejp is on a distinguished road
 
Posts: 10
Join Date: Jun 2008
Default 07-19-2008, 03:35 PM

Oh, great. What I actually did was the same thing, just a bit longer:

str_replace(chr(13).chr(10), '<br>', $r);

Thanks though!
Reply With Quote
(#7 (permalink))
Old
Junior Member
geshan is on a distinguished road
 
Posts: 2
Join Date: Jul 2008
Default 07-20-2008, 01:39 PM

YOu might also want to use stripslashes() function of php.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com