Logician Posted November 6, 2011 Share Posted November 6, 2011 Does anyone know why I am not getting lines brakes when using \n when inserting the following into a MySQL field? '".date(DATE_RFC822)."\nWRITING ORDER TO DATABASE\n' Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/ Share on other sites More sharing options...
trq Posted November 6, 2011 Share Posted November 6, 2011 Not without seeing your code. Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285449 Share on other sites More sharing options...
Logician Posted November 6, 2011 Author Share Posted November 6, 2011 I've narrowed it down to being MySQL, because when I try to insert directly, it still doesn't work. The code I am using is: INSERT INTO orders (test) values ('FOO\nBAR\n'); It should be sitting: foo bar Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285450 Share on other sites More sharing options...
trq Posted November 6, 2011 Share Posted November 6, 2011 \n means nothing to MySql. Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285461 Share on other sites More sharing options...
Logician Posted November 6, 2011 Author Share Posted November 6, 2011 I see. Damn it! Do you know how making a line brake can be done in MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285475 Share on other sites More sharing options...
floridaflatlander Posted November 6, 2011 Share Posted November 6, 2011 What do you want a line break in mysql or a line break on a web page? Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285477 Share on other sites More sharing options...
haku Posted November 6, 2011 Share Posted November 6, 2011 Exactly. Are you looking at it in a mysql GUI? Or are you printing it to a page? Or to a file? Also, it's 'break', not 'brake' Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285483 Share on other sites More sharing options...
fenway Posted November 6, 2011 Share Posted November 6, 2011 Nothing wrong with the line break -- but unless you're getting a mysql error, you have some other, non-DB problem. Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285507 Share on other sites More sharing options...
Logician Posted November 6, 2011 Author Share Posted November 6, 2011 OK, I am back on using MySQL with PHP again. This is what I just tried. Its being entered into the MySQL field, but there are not line brakes. $query = "INSERT INTO orders (events) VALUES ('".date(DATE_RFC822)."\nWRITING ORDER TO DATABASE\n')"; Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285521 Share on other sites More sharing options...
Logician Posted November 6, 2011 Author Share Posted November 6, 2011 So, it was working all along. I only noticed now when I checked MySQL from terminal. I got it working the way I needed it using the HTML element <PRE> Solved. Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285535 Share on other sites More sharing options...
haku Posted November 6, 2011 Share Posted November 6, 2011 I'm assuming you mean that the line breaks weren't happening in your HTML (you still haven't really explained). If so, and you are using PHP, you can use nl2br() to convert line breaks to <br /> tags. You won't have to use <pre> tags this way. Quote Link to comment https://forums.phpfreaks.com/topic/250548-line-failing-to-brake/#findComment-1285593 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.