Could someone tell me how to add a new line in a text that I enter in a MySql table?
I tried using the '\n'
in the line I entered with INSERT INTO
statement but '\n'
is shown as it is.
Actually I have created a table in MS Access with some data. MS Access adds new line with '\n'
. I am converting MS Access table data into MySql . But when I convert, the '\n'
is ignored and all the text is shown in one single line when I display it from MySql table on a PHP form.
Can anyone tell me how MySQL can add a new line in a text? Awaiting response, thanks!!
Press ALT+ENTER to insert the line break.
Just put the output text between <pre></pre> tags, that will preserve the line breaks.
If you're OK with a SQL command that spreads across multiple lines, then oedo's suggestion is the easiest:
INSERT INTO mytable (myfield) VALUES ('hi this is some text
and this is a linefeed.
and another');
I just had a situation where it was preferable to have the SQL statement all on one line, so I found that a combination of CONCAT_WS()
and CHAR()
worked for me.
INSERT INTO mytable (myfield) VALUES (CONCAT_WS(CHAR(10 using utf8), 'hi this is some text', 'and this is a linefeed.', 'and another'));
in an actual SQL query, you just add a newline
INSERT INTO table (text) VALUES ('hi this is some text
and this is a linefeed.
and another');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With