Forum Moderators: coopster

Message Too Old, No Replies

Text not wrapping

text wrap

         

rhamej

8:59 am on Mar 18, 2005 (gmt 0)

10+ Year Member



Hellp everyone :-)
I have a small problem with data being pulled from a mySQL db. I created a textarea that pulls the content from a table row. The user can then either add or change what they want. My first problem was that when hitting the enter key, it was not adding a line break. I fixed this by adding the nl2br, which now works. :-) But now, say you are just typing and you get to the edge of the textarea, the text moves to a new line. But when viewing the text on the actual page, it doesn't move to a new line, it just creates one long line of text even though I have it in a 340px wide table.
Any ideas?
Thanks.
Josh

rhamej

9:04 am on Mar 18, 2005 (gmt 0)

10+ Year Member



You can see what I am talking about here. THis is the PHP page that gets the data. If you resize the window, you will see a horizontal scrollbar appear. The text right now is much longer than the 320px wide table its in. I always thought text woudld wrap in a table no matter what. errg. I need asprin.

snipped url

[edited by: coopster at 11:35 am (utc) on Mar. 18, 2005]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

dreamcatcher

9:20 am on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Josh,

Yes, this is how a textarea works, it doesn`t wrap automatically. What you need is the wordwrap() [uk2.php.net] function.

Hope that helps.

dc

rhamej

5:27 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Sorry, I wanst clear what I meant. The textarea that changes the data actually displays it fine. It's the normal page (the one I linked to above) that only has a table in it to display the text is messing up.
Its just a basic PHP script that connects to the database, loops through the table to disaply the News column. Thats it. I was always under the assumption that text would wrap in <td> no matter what. But its stretching the table past what I defined the width as. Im confused. :-(

dreamcatcher

7:18 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, personal URLS are not allowed on the board.

I think table stretching will occur whether you have specifed percentage or pixels for your size. When you display your data, try using the function I mentioned.

So, if your database variable is $row['message'], use:

wordwrap($row['message'], 70, "\n", 1);

This example wraps every 70 characters.

dc

rhamej

7:38 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Ahhh. I got ya now. Well, thats kinda retarded if you ask me. Seems silly to create a seperate function to display html text that normally wraps. Owell, back to the drawing board. Thanks.
Sorry about the URL, didn't know that. :-)

Josh