Jump to content

[SOLVED] Saving Format of text to database


nemesis.2002

Recommended Posts

So i'm making a php website, this is actually my first php site this complex. But i've run into a snag. My client updates his website trough a admin page that sends all the info to a mysql database but it dosen't save the format on the way he typed it in. For example: if he presses enter twice in a row in the textarea form he wants it to go to the next line and skip a line, but what ends up happening it displays in one line.  Is their a way to do this in php? So that an "enter" key stroke will generate a <br> tag or something? 

So if $text_from database is what i bring out from mysql i should do this

 

$query = "SELECT * FROM text_fill ";

  $mysql_stuff = mysql_query($query, $mysql_link);

  while($row = mysql_fetch_row($mysql_stuff)) {

    $id = $row[0];

    $$text_from database = $row[14];

 

$string_from_db = $text_from database;

echo nl2br($string_from_db);

print("$string_from_db");

}

and that should format it properly?

Try this:

<?php
$query = "SELECT * FROM text_fill ";
  $mysql_stuff = mysql_query($query, $mysql_link);
  while($row = mysql_fetch_row($mysql_stuff)) {
    $id = $row[0];
    $$text_from database = $row[14];

$string_from_db = $text_from database;
echo nl2br($string_from_db);
}
?>

 

Both print and echo will output the text. I just removed the print line.

 

Also, what format is the text stored in the database? Is it Varchar, text?

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.