Jump to content

[SOLVED] Adding breaks problem?


A JM

Recommended Posts

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

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'];
}
?>

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'];

 

Archived

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

×
×
  • Create New...

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.