Jump to content


Photo

Box Becoming To Wide


  • Please log in to reply
6 replies to this topic

#1 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 August 2006 - 09:44 PM

I have a guest book script (very simple) that l have made and modified to work with usernames.  However in the testing stage l posted some junk to see what would happen and it went all the way across the page and kept on going.

My code is as follows:

// Define $color=1
$color=1;
echo '<table width="950" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">';

while($rows=mysql_fetch_array($result)){

// If $color==1 table row color = #FFFFCC + #CCFFFF
if($color==1){

echo "
<td>
<tr>
<table align='center' width='800' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>
<tr>
<td width='150' valign='top' bgcolor='#CCFFFF'><font size='-1'>
<strong>Posted By:</strong>".$rows['username']."<br />
<strong>Date: </strong>".$rows['datetime']."<br /></font></td>

<td valign='top' width='650' bgcolor='#FFFFCC'>".$rows['comment']."</td>
</tr>
<br />
</table></td>
</tr>";

//<td width='10' valign='top' bgcolor='#CCFFFF'><a href='deletepost.php?postid=".$rows['userid']."'>X</a></td>
// Set $color==2, for switching to other color
$color=2;
}

// When $color not equal 1, use this table row color #FFFF99 + #CCFFFF
else {
echo "
<td>
<tr>
<table align='center' width='800' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>
<tr>
<td width='150' valign='top' bgcolor='#CCFFFF'><font size='-1'>
<strong>Posted By:</strong>".$rows['username']."<br />
<strong>Date: </strong>".$rows['datetime']."<br /></font></td>

<td valign='top' width='650' bgcolor='#FFFF99'>".$rows['comment']."</td>
</tr>
<br />
</table>
</td>
</tr>
";

// Set $color back to 1
$color="1";
}
}

echo '
</table>';
mysql_close(); //close database
echo "<br />";

To help you visualize the problem a link to a screen shot is below:

http://img350.images...problem1qk4.jpg

Also for some reason the blue box gets smaller on this reply when it should be 150px in width..

Your help is greatly appreciated,

dual_alliance

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 09 August 2006 - 11:44 AM

In your 'junk' test you made one word of approx. 300 characters. That cannot split, so your box get wider and wider. Try to test with a normal sequence of words and see if the problem persists.

RTFM is an almost extinct art form, it should be subsidized.

#3 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 11:50 AM

Thanks that fixed it.  But l still have the problem of it adding no blank spaces :/

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 August 2006 - 12:25 PM

What do you mean by 'adding no blank spaces'?
Legend has it that reading the manual never killed anyone.
My site

#5 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 12:32 PM

Sorry l was away with the fairy's when l said that, l meant it adds no new lines.

say if l have:

This is
a
test

And when l insert it, it is displayed as:

This is a test


#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 August 2006 - 01:33 PM

Use the nl2br() function - it converts 'newlines' to html br statements

In your output code, change $rows['comment'] to nl2br($rows['comment'])
Legend has it that reading the manual never killed anyone.
My site

#7 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 03:22 PM

Cheers AndyB that worked perfectly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users