adam_gardner Posted April 8, 2006 Share Posted April 8, 2006 hi guys,I have a field set-up to store a users comments - like a message.how can i get it to output again with the correct formatting they gave it? (i.e. line breaks etc.) because all my text just runs togetheris it a php thing or a mysql formatting issue?ps. my data appears as I typed it when viewed in phpmyadmin, but not when i echo it.any help would be great!thanks!Adam Link to comment https://forums.phpfreaks.com/topic/6906-text-formatting-in-php-mysql/ Share on other sites More sharing options...
desithugg Posted April 8, 2006 Share Posted April 8, 2006 [!--quoteo(post=362876:date=Apr 8 2006, 06:27 PM:name=adam_gardner)--][div class=\'quotetop\']QUOTE(adam_gardner @ Apr 8 2006, 06:27 PM) [snapback]362876[/snapback][/div][div class=\'quotemain\'][!--quotec--]hi guys,I have a field set-up to store a users comments - like a message.how can i get it to output again with the correct formatting they gave it? (i.e. line breaks etc.) because all my text just runs togetheris it a php thing or a mysql formatting issue?ps. my data appears as I typed it when viewed in phpmyadmin, but not when i echo it.any help would be great!thanks!Adam[/quote]umm not sure what you mean but try this<?php$link = mysql_connect('localhost', 'username', 'password');if (!$link) {die('Could not connect: ' . mysql_error());}$db_selected = mysql_select_db('tpf');if (!$db_selected) {die('Could not select database: ' . mysql_error());}$result = mysql_query("SELECT message FROM inbox WHERE messageID = 'message id');if (!$result) {echo 'Could not run query: ' . mysql_error();exit;}$row = mysql_fetch_row($result);echo $row[0]; // 42?>and make it so its in a table and even with html variables like <center><br> etcc.. it should display properly Link to comment https://forums.phpfreaks.com/topic/6906-text-formatting-in-php-mysql/#findComment-25098 Share on other sites More sharing options...
adam_gardner Posted April 8, 2006 Author Share Posted April 8, 2006 [!--quoteo(post=362877:date=Apr 8 2006, 05:31 PM:name=desithugg)--][div class=\'quotetop\']QUOTE(desithugg @ Apr 8 2006, 05:31 PM) [snapback]362877[/snapback][/div][div class=\'quotemain\'][!--quotec--]umm not sure what you mean but try this<?php$link = mysql_connect('localhost', 'username', 'password');if (!$link) {die('Could not connect: ' . mysql_error());}$db_selected = mysql_select_db('tpf');if (!$db_selected) {die('Could not select database: ' . mysql_error());}$result = mysql_query("SELECT message FROM inbox WHERE messageID = 'message id');if (!$result) {echo 'Could not run query: ' . mysql_error();exit;}$row = mysql_fetch_row($result);echo $row[0]; // 42?>and make it so its in a table and even with html variables like <center><br> etcc.. it should display properly[/quote]nope, not sure you got me -- here's my php codethe problem is, like i'm doing in this post, putting line breaks everywhere, my text seems to run together.here's the barebones of my php - very straight forward really.<?$query="SELECT * FROM messages WHERE toID = $CID";$result=mysql_query($query) or die (mysql_error() . "\nActual query: " . $query);$num=mysql_numrows($result);echo "Inbox";$i=0;while ($i < $num) {$Msg=mysql_result($result,$i,"message");echo "Message :: $Msg";$i++;}?> Link to comment https://forums.phpfreaks.com/topic/6906-text-formatting-in-php-mysql/#findComment-25105 Share on other sites More sharing options...
kenrbnsn Posted April 9, 2006 Share Posted April 9, 2006 Line breaks in HTML are made by inserting the "<br />" tags, not by outputing a newline character. You can either output your text between "<pre>" and "</pre>" tags which preserve the new lines or use the function nl2br() on your output text:[code]<?php echo 'Message :: ' . nl2br($Msg); ?>[/code] which places the "<br />" tag before each newline character.Ken Link to comment https://forums.phpfreaks.com/topic/6906-text-formatting-in-php-mysql/#findComment-25153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.