dual_alliance Posted August 8, 2006 Share Posted August 8, 2006 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 + #CCFFFFif($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 + #CCFFFFelse {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 databaseecho "<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 Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 9, 2006 Share Posted August 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted August 9, 2006 Author Share Posted August 9, 2006 Thanks that fixed it. But l still have the problem of it adding no blank spaces :/ Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 9, 2006 Share Posted August 9, 2006 What do you mean by 'adding no blank spaces'? Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted August 9, 2006 Author Share Posted August 9, 2006 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 isatest[/code]And when l insert it, it is displayed as:[code]This is a test[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 9, 2006 Share Posted August 9, 2006 Use the nl2br() function - it converts 'newlines' to html br statementsIn your output code, change $rows['comment'] to nl2br($rows['comment']) Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted August 9, 2006 Author Share Posted August 9, 2006 Cheers AndyB that worked perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.