Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    May 2003
    Location
    Scotland
    Posts
    39
    Member #
    1316
    Hi,
    I'm a newbie to SQL and PHP.

    I was wondering how you do the following:

    I want someone to type stuff into a form. This then gets submitted to the SQL database, but when i go to view it it displays properly, but all the text is all together there are no line breaks, gaps, etc.

    For example, it should look like this:
    Code:
    This is just a sample, as you can see there is a gap between this line and the next.
    
    See what i mean?
    But SQL displays it like this:
    Code:
    This is just a sample, as you can see there is a gap between this line and the next. See what i mean?
    Does anybody know how what to do to make it display like the 1st instance or point me in the right direction?

    Thanks
    Craig

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Try replacing CARRIAGE RETURN characters with <br>, like this:

    SELECT REPLACE(column_name, '\n', '<br>') column_alias FROM database_name

    "column_alias" is the name that you will reference to retrieve the column from your resultset.

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The reason you have to do this is because HTML ignores line breaks. You have to specify them with the HTML <br> tag.

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Code:
    SELECT REPLACE(column_name, '\n', '<br>') AS column_alias FROM database_name;
    ...in MySQL, at least.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Or.... php has a function nl2br (www.php.net/nl2br) which does this automatically to save time...

    Code:
    $mytext = nl2br($mytext);
    echo $mytext;
    Also you might want to look into function htmlspecialentities() if you're posting stuff from/to a mysql db certain characters (such as apostrophies) really gum the works up.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  7. #6
    Member
    Join Date
    May 2003
    Location
    Scotland
    Posts
    39
    Member #
    1316
    Thanks for the info. It's much appreciated.

    Craig

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    LOL... i'm so confused with AS for aliases lately.

    Microsoft SQL Server - supports it, but doesn't require it.
    Oracle - doesn't support it at all.
    Informix - supports it, but doesn't require it.
    MySQL - requires it?

    I've never read ANSI 92 standards for aliasing. I used to use AS explicitly until I started working with Oracle. Then I reverted to using nothing, because it's the common denominator.

    Can someone test MySQL to verify that it's required?

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Nevermind... just read into it and Oracle DOES support it.

    I'm guessing that it's ANSI-92 standard to use it, but optional for most databases.

    I'm gonna start using it again.

  10. #9
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ah, I read into it further... Oracle standard is not using AS, because it wasn't supported previously. SQL Server is the same way. All databases now support AS now, though, because it's ANSI-92, and they recommend using it.

    Whew !!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:40 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com