Jump to content


Displaying data from MySQL

  • Please log in to reply
4 replies to this topic

#1 wigwambam

  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 27 March 2006 - 09:58 PM

My 1st post.. hi everyone.

I have written a guestbook in PHP using MySQL. When I write the message to the database I use "mysql_real_escape_string" to convert the string.

This is my problem. When I display the info from the database (using echo) it does not display new lines.

e.g. someone signs guestbook with:

My name is Fred,
Great site.

My output is:

Hello, My name is Fred, Great site.

How do I get the '\n or <br> chars in there?

#2 Eddyon

  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationEngland

Posted 27 March 2006 - 11:55 PM

After you have pulled the string from the database but before you echo the string doing something like this:

$comment = str_replace("\n", "<br />", $comment);

Thats just guessing you are using something like comment for your variable, just change it to what ever you are using and it should work, let us know how you get on.

#3 earl_dc10

  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 28 March 2006 - 12:12 AM

or you could use nl2br
echo nl2br($comment);

this converts all \n's to <br>'s
got a problem? Google helps many of those in need

#4 wigwambam

  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 28 March 2006 - 07:35 AM

great replies, thanks for your help. I knew there would be a simple solution, the hard part is finding the info - I'm currently converting from ASP to PHP and know where to ask in future, thanks again.

#5 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 March 2006 - 09:41 AM

You can easily find what you need in over at php.net which holds the fine and easy to follow manual too. First always check over at [a href=\"http://www.php.net/manual/en/\" target=\"_blank\"]http://www.php.net/manual/en/[/a] and have little browse through the manual to see if there is anythink there can help you.

If you cant find anythink then just post here and we will help!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users