[php][mysql]Select From issues.

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by taekwondokid42, Feb 29, 2008.

  1. taekwondokid42

    taekwondokid42 New Member

    Messages:
    268
    Likes Received:
    0
    Trophy Points:
    0
    In my mysql entries, many of the entries contain [enter] characters. (These are also known as /n or newline)


    When I pull them from the table, all of the /n are turned into spaces. Does anybody know how I can fix this?


    I am currently using mysql_query("SELECT * FROM ...");
     
  2. jeyson65

    jeyson65 New Member

    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    These newline characters are being returned by the query, it's just that the browser ignores them. You need to replace the newline character with a break tag. Both MySQL and PHP have replace functions so here are your options:

    1. MySQL - mysql_query("SELECT REPLACE(<column_name>, '\n', '<br />'), column2, ... FROM...")
    2. PHP - Once you have the string, call str_replace('\n', '<br />', <text containing newline>).

    I didn't actually try this but I've done it in other databases and languages. You may have to escape the '\' character (with an extra '\').

    I hope this helps.
     
  3. stainnn

    stainnn New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    maybe you should use php's function nl2br($string_that_contains_newline) - it converts new line to <br /> tag
     
  4. taekwondokid42

    taekwondokid42 New Member

    Messages:
    268
    Likes Received:
    0
    Trophy Points:
    0
    Thank you, both of you.
     

Share This Page