Jump to content

Archived

This topic is now archived and is closed to further replies.

dual_alliance

Box Becoming To Wide

Recommended Posts

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:

[code=php:0]// 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 />";[/code]

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

[url=http://img350.imageshack.us/img350/4964/problem1qk4.jpg]http://img350.imageshack.us/img350/4964/problem1qk4.jpg[/url]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
What do you mean by 'adding no blank spaces'?

Share this post


Link to post
Share on other sites
Sorry l was away with the fairy's when l said that, l meant it adds no new lines.

say if l have:

[code]This is
a
test[/code]

And when l insert it, it is displayed as:

[code]This is a test[/code]

Share this post


Link to post
Share on other sites
Use the nl2br() function - it converts 'newlines' to html br statements

In your output code, change $rows['comment'] to nl2br($rows['comment'])

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.