0

what's the proper syntax to account for a newline in "text" field? for example,

   mysql_query("select * from table where misc_note='hello\nworld'")

isn't working

Zack Burt
  • 8,257
  • 10
  • 53
  • 81
  • 1
    Text fields can't display newlines so I'm not sure why you're allowing them to be entered in the first place. – Joe Phillips Aug 30 '10 at 23:28
  • 2
    can you post the `select hex(misc_note) from table where id = ` to see if its actually \n or \r\n or maybe some spaces before or after? – Imre L Aug 30 '10 at 23:31
  • Imre: 444F204E4F542063616C6C2073746576656E2120696E73746561642C2063616C6C204E6F656C6C653A202832313229207878782D78787878203A290D0A – Zack Burt Aug 31 '10 at 00:10
  • 3
    it has `0D0A` at the end. this indicates that you should use `\r\n` instead of `\n` and you should be fine. – Imre L Aug 31 '10 at 00:24

3 Answers3

1

If you want mysql way then: char(10) or char(13),char(10) depending if u want \n or \r\n

mysql_query("select * from table where misc_note=concat('hello',char(13),char(10),'world')")

EDIT: however it seems you may need this instead:

mysql_query("select * from table where misc_note like 'searchstring%'")

% indicates any number of any character that can occur, means you search for all notes startig with 'searhstring'.

Imre L
  • 6,159
  • 24
  • 32
0

You are probably outputting it to text field and not in textarea. Only textarea can display new lines.

If \n is still not working you can try \r\n.

knagode
  • 5,816
  • 5
  • 49
  • 65
0

There is a PHP Constant, PHP_EOL, which holds the End Of Line character specific to the system.

More information on this can be found at: When do I use the PHP constant "PHP_EOL"?

Not really sure if this would help you in your certain situation, but yea, just throwing it out there.

Community
  • 1
  • 1
Jim
  • 18,673
  • 5
  • 49
  • 65