SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: <br>QUA

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2002
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <br>QUA

    I have one QUA about my sql.
    PHP Code:
    create table Hideo(comment text); 
    When I write comment in my database, how can I <br> my comment.

    because I don't want to write my comments vartically.

    Should I do like this
    PHP Code:
    insert into Hideo(comment)values('Hi how are you doing. I am fine and you? My name is-------. I am from-----. Nice to meet you'); 
    my comment is long, so I would like to use <br>

    how can I use <br> with mysql commend

    Thanks

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make new lines in the comment before inserting it, and replace the "\n" characters with "<br>" when you display them...
    PHP Code:
    <?
    // The comment you want to insert:
    $comment "Hi how are you doing. 
        I am fine and you? 
        My name is-------. 
        I am from-----. 
        Nice to meet you"
    ;
    $sql "insert into hideo (comment) values ('$comment')";
    mysql_connect("localhost""root""root");
    mysql_select_db("test");
    mysql_query($sql);
    // Another way to do the same thing:
    $comment "Hi again!\nHow are you doing today?\nFine fine";
    $sql "insert into hideo (comment) values ('$comment')";
    mysql_query($sql);
    // OK, now get all comments:
    $sql "select * from hideo";
    $rows mysql_query($sql);
    while(
    $row mysql_fetch_array($rows))
    {
        
    $comment str_replace("\n""<br>"$row[0]);
        echo 
    "<p>$comment</p>";
    }
    ?>
    Remember:
    \n is the new line in the text,
    <br> is the html tag for a new line


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
  •