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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.