SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New line break in php

    I want to put a new line break on the records that i am retrive using CVS file. I am retrieving data from mysql database into a csv file but could not break up the data when it is displayed. This is how it is displaying below:

    1,4,Yes ,1\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n3,4,Not sure ,3\nenabled\n1,4,Yes


    I need to put a new line break on the code below. Can someone identify my error or tell me how to use new line break in php please.

    while ($row = mysql_fetch_array($result)) {
    // this sticks the results row by row into an array called $row.
    // rows are called via $array_name["COLUMN_NAME"]
    //$out =
    $out .= $row["id"].',';
    $out .= $row["id_question"].',';
    $out .= $row["answer"].',';
    $out .= $row["position"].'\n';
    $out .= $row["status"].'\n';


    echo $out;
    Thanks.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The \n needs to be inside "" not ''.
    PHP Code:
    $out .= $row["position"]."\n";
    $out .= $row["status"]."\n"
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New Line break

    Thanks, it works but is it still alright showing this on the browser:

    1,4,Yes ,1,enabled 1,4,Yes ,1,enabled 2,4,No ,2,enabled 1,4,Yes ,1,enabled 2,4,No ,2,enabled 3,4,Not sure ,3,enabled 1,4,Yes ,1,enabled 2,4,No ,2,enabled

    while in the .csv file, it shows properly like:

    1 4 Yes 1 enabled
    2 4 No 2 enabled
    3 4 Not sure 3 enabled
    4 5 Yes 1 enabled

    Is there any thing to correct with the display of the browser?

    Thanks.

  4. #4
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In HTML, a line break is <br /> instead of \n.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New Line break

    This is a php code. this "\n" works but the way the csv.php script displays it on the browser looks to confusing while it is is displayed properly in the .cvs file in excel.
    Thanks.

  6. #6
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Quote Originally Posted by php.net
    What is PHP?

    PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
    PHP generates HTML (and pretty much anything else), which is then displayed in the browser. The browser has no idea and could not care less whether the page is static HTML or generated by PHP.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this "\n" works but the way the csv.php script displays it on the browser looks to confusing
    You need to learn something called "html". Html is the language you use to tell browsers how to display things like text, forms, and images. Anything you need to display in a browser, must be displayed using html markup. On the other hand, you write plain text to a text file. Since you don't view text files in a browser, you don't need to use html when you write to a text file.

    When you use php to write to a web page, you must write html to the web page.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    You need to learn something called "html".
    There's a few things you need to learn too


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •