Skip to main content
Inspiring
November 28, 2007
Question

Hold carriage returns in PHP MySQL database?

  • November 28, 2007
  • 2 replies
  • 736 views
I'm creating a limited news database for a not-for-profit site and I want to let admin users write a long entry which may include multiple paragraphs (i.e. carriage returns) and even bold text for subheadings would be nice. I haven't been able to find out the proper code and DB settings to allow users to do this.

Anyone have a simple solution?
This topic has been closed for replies.

2 replies

Inspiring
November 28, 2007
The way I handle text formatting with dynamic data is to carefully construct
your DB with formatting in mind
Create separate fields for headlines and copy. When you call the data to
your web page surround the heading with the desired tag. Of course you will
not always have a heading, so, to eliminate empty spaces add a conditional
statement to ignore the field if it is null.

like this:

database:
news_id
news_headline1
news_copy1
news_headline2
news_copy2

web page:
<?php if (strlen($row_getNews['news_headline1']) > 0) {?>
<h3><?php echo $row_getNews['news_headline1']; ?></h3>
<?php }?>
<p><?php echo $row_getNews['news_copy1']; ?></p>
<?php if (strlen($row_getNews['news_headline2']) > 0) {?>
<h3><?php echo $row_getNews['news_headline2]; ?></h3>
<?php }?>
<?php if (strlen($row_getNews['news_copy2']) > 0) {?>
<p><?php echo $row_getNews['news_copy2']; ?></p>
<?php }?>

Jeff


"Justin from Indiana" <webforumsuser@macromedia.com> wrote in message
news:fiimo4$33$1@forums.macromedia.com...
> I'm creating a limited news database for a not-for-profit site and I want
> to
> let admin users write a long entry which may include multiple paragraphs
> (i.e.
> carriage returns) and even bold text for subheadings would be nice. I
> haven't
> been able to find out the proper code and DB settings to allow users to do
> this.
>
> Anyone have a simple solution?
>


Inspiring
November 30, 2007
Justin from Indiana wrote:
> But the user posting stories is going to need more flexibility for bulleted lists, etc.

In that case, you need to store the HTML in the database. You might want
to look into FCKEditor ( http://www.fckeditor.net/).

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
December 5, 2007
Took a quick look. It appears to work much like the interface for these posts. Hope it's not to problematic to work into my admin pages...
Inspiring
November 28, 2007
Justin from Indiana wrote:
> I'm creating a limited news database for a not-for-profit site and I want to
> let admin users write a long entry which may include multiple paragraphs (i.e.
> carriage returns) and even bold text for subheadings would be nice.

Carriage returns are stored normally in a database. However, they seem
to disappear when displayed onscreen. This is because HTML ignores extra
whitespace. If you use View Source in a browser, you'll see the carriage
returns are actually there. The solution is simple with PHP. Just pass
the material retrieved from the database to nl2br().

http://docs.php.net/manual/en/function.nl2br.php

If you're using Dreamweaver CS3, you can add nl2br() to dynamic text by
double-clicking the Dynamic Text listing in the Server Behaviors panel,
and selecting Convert - New Lines to BRs from the Format menu.

To store bold text in the database, just surround the text with <strong>
tags.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/