views:

482

answers:

4

Hi

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 !!

+1  A: 

First of all, if you want it displayed on a PHP form, the medium is HTML and so a new line will be rendered with the <br /> tag. Check the source HTML of the page - you may possibly have the new line rendered just as a line break, in which case your problem is simply one of translating the text for output to a web browser.

David M
+2  A: 

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');
oedo
A: 

It sounds to me like you're confusing the contents of the table some particular tool's rendering of those contents.

I presume you're using the command line (shell) client, the mysql prompt both to enter and to display the text in this column. I'm also guessing that you're \n is being stored as a newline and that it's only the way it's being presented that's causing your confusion.

Try using a GUI tool for accessing your MySQL data.

Jim Dennis
A: 

In SQL or MySQL you can use the char or chr functions to enter in an ascii 13 for carriage return line feed, the \n equivilent. But as @David M has stated, you are most likely looking to have the html show this break and a br is what will work.

RandyMorris