Jump to content

Recommended Posts

No, no, no!

If it's stored in the database as 3 lines, like so:

 

Hey
this is three
lines!

 

Then all you need to do is grab the data from the database and use nl2br() on it. You shouldn't be inserting HTML tags into the database when what it's doing is perfectly normally.

 

So you get your data:

 

$connect = mysql_connect("localhost", "root", "");
mysql_select_db("database");

$query = mysql_query("SELECT textarea FROM table WHERE id='1'") or die(mysql_error()); //just an example query.
$data = mysql_fetch_assoc($query); //Fetch the data

echo $data['textarea']; //This will display it all on one line, which is wrong.

echo "<br /><br />";

echo nl2br($data['textarea']); //After performing the nl2br() function on it it'll convert all \n characters to the HTML equivalent <br />

 

Make sense?

Okay I agree about not storing <br /> in the database as its actually NOTHING to do with the data being stored, however I'm pretty sure if this is true the whole problem here is attempting to store FORMATTING in the database which is also wrong - if these values are fundamentally seperate (they are all different qualifications) they should be stored within different records.  I am correct?

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.