A JM Posted August 31, 2009 Share Posted August 31, 2009 I'm trying to add breaks to my $comment line but its not working as I anticpiated, can someone help me out with this? It just runs on with breaking after each item in the query...? <?php $query_rstcomments = "SELECT comment FROM comments; $rstcomments = mysql_query($query_rstcomments, $dbconn) or die(mysql_error()); while ($rec=mysql_fetch_assoc($rstcomments)){ $comment = $comment . "\n" . $rec['comment']; } ?> <textarea cols="40" wrap="virtual" disabled="disabled"><?php echo $comment; ?></textarea> Thanks. A JM, Link to comment https://forums.phpfreaks.com/topic/172522-solved-adding-breaks-problem/ Share on other sites More sharing options...
Batosi Posted August 31, 2009 Share Posted August 31, 2009 <?php $comment = $comment . "\n" . $rec['comment']; ?> Link to comment https://forums.phpfreaks.com/topic/172522-solved-adding-breaks-problem/#findComment-909516 Share on other sites More sharing options...
A JM Posted August 31, 2009 Author Share Posted August 31, 2009 Not sure why the backslash didn't show up but that is what I'm currently using? escaping I'm guessing is my problem...? <?php $query_rstcomments = "SELECT comment FROM comments; $rstcomments = mysql_query($query_rstcomments, $dbconn) or die(mysql_error()); while ($rec=mysql_fetch_assoc($rstcomments)){ $comment = $comment . '\n' . $rec['comment']; } ?> Link to comment https://forums.phpfreaks.com/topic/172522-solved-adding-breaks-problem/#findComment-909590 Share on other sites More sharing options...
Alex Posted August 31, 2009 Share Posted August 31, 2009 At first glance I see 2 things: 1. You're missing a double quote: $query_rstcomments = "SELECT comment FROM comments; should be: $query_rstcomments = "SELECT comment FROM comments"; 2. For a line break "\n" to work it must be wrapped in double quotes, otherwise it'll just be read as a string. So.. $comment = $comment . '\n' . $rec['comment']; Should be: $comment = $comment . "\n" . $rec['comment']; Link to comment https://forums.phpfreaks.com/topic/172522-solved-adding-breaks-problem/#findComment-909595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.