Jump to content

[SOLVED] mysql newline help


sasori

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?

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.