LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-26-2004, 09:52 PM   #1
Boby
Member
 
Registered: Feb 2004
Location: Sighisoara/Cluj-Napoca (Romania)
Distribution: CentOS 4, Fedora Core 6
Posts: 781

Rep: Reputation: 31
PHP - how to put an auto <br> at end of line


hello

i'm a writing on a guestbook in PHP with MySQL DB. This is my output file:


...
while($r=mysql_fetch_array($result))
{
echo "<br><table align='center' cellpadding='1' cellspacing='1' class='gbook'>";
echo "<tr>";
echo "<td>";
echo "<table align='center' cellpadding='1' cellspacing='1' class='gbook2'>";
echo "<tr>";
echo "<td align='left'>Posted by <b>$r[name]</b> at <b>$r[date]</b></td><td align='right'><a href='mailto:$r[email]'>e-mail</a> | <a href='$r[url]' target='_blank'>url</a></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "<tr>";
echo "<td align='left'>$r[message]</td>";
echo "</tr>";
echo "</table>";
}
...


the tables width is 590px. if the message is very long my table is enlarging to infinite. how can i set it or what command do i need to put an automatic <br> if the message comes to the end of line.
i am using CSS to format the tables.

thanX
 
Old 04-26-2004, 11:44 PM   #2
socket9001
LQ Newbie
 
Registered: Dec 2003
Location: Israel
Distribution: Slackware
Posts: 21

Rep: Reputation: 15
try using nl2br to break the message....
www.php.net/nl2br
 
Old 04-27-2004, 10:04 AM   #3
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
that sounds like an html problem. If i set my table with to say 500px and the text spans further than that then it will automatically start a new row down. I've never seen it expand a cell's width further than what you declare. Maybe try adding width="590" the your <td> tags instead of just the table tag.
 
Old 04-27-2004, 07:30 PM   #4
Boby
Member
 
Registered: Feb 2004
Location: Sighisoara/Cluj-Napoca (Romania)
Distribution: CentOS 4, Fedora Core 6
Posts: 781

Original Poster
Rep: Reputation: 31
it still don't works!!
Quote:
You don't want to use nl2br() when you save your text in a database
i really don't know what to do...my long message makes the whole page look very bad. i tried to put a width="590px" in the <td> tag but it still won't work.is there something wrong with my html? i don't thing, but maybe i made a mistake. pleeeaseeee heeelp me out of that!

thanX
 
Old 04-28-2004, 09:10 AM   #5
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
the only time i use the px suffix is in a css or style tag. width="590" is automatically interpreted as 590 pixels. Try removing the px.
 
Old 04-28-2004, 04:27 PM   #6
Boby
Member
 
Registered: Feb 2004
Location: Sighisoara/Cluj-Napoca (Romania)
Distribution: CentOS 4, Fedora Core 6
Posts: 781

Original Poster
Rep: Reputation: 31
i hate it and i hate it again......and again....

i removed the px but...nothing changed
 
Old 05-04-2004, 10:12 AM   #7
Ohmu
LQ Newbie
 
Registered: Jan 2004
Location: Estonia
Distribution: Gentoo
Posts: 20

Rep: Reputation: 0
like socket9001 suggested...
change:
echo "<td align='left'>$r[message]</td>";
to:
echo '<td align="left">'.nl2br (trim ($r[message])).'</td>';

should work imo...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Should I put the swap partition at the beginning or the end of the drive? mpyusko Slackware - Installation 32 04-11-2011 06:07 AM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 09:42 AM
end of line script paul_mat Linux - Software 1 11-04-2005 01:06 AM
/r at end of line in script silence Linux - General 1 08-21-2004 08:25 AM
end of line character hyperriven Linux - General 1 04-07-2004 08:24 PM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration