SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    MT.Waverly
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Echo database text field to a Javascript array.

    Hi all,

    I’m trying to echo a text field from the database to a JavaScript array. But if the user has struck <Enter> while entering data in to the textaria

    i.e. First line…..<Enter>
    Second liner…..

    The string I echo into the JavaScript breaks into several lines thus the code doesn’t work. Is there anyway that I can get the string to echo in one line?

    // PHP code

    <?php
    echo"<script language = \"javascript\">";
    $query = "SELECT spl_ins FROM orders";
    $result = mysql_query($query);
    $count=0;
    while ($row = mysql_fetch_row($result))
    {
    echo "order_arr['.$count.']=\"$row[0]\";"."\r\n";
    $count++;
    }
    echo"</script>";
    ?>


    // Result

    <script language = "javascript">

    order_arr[0]="line one...";
    order_arr[1]="line one...
    line two...";
    //(Problem the string is broken in to two lines)

    </script>

    Camellia.

  2. #2
    Is Still Alive silver trophybronze trophy RetroNetro's Avatar
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    6,883
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello

    This forum is for questions concerning the Sitepoint Community.

    A moderator will move it eventually to the correct forum.

    Johnny


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
  •