Nightshade123 Posted June 30, 2009 Share Posted June 30, 2009 Please help.. this is driving me insane! This echo "------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n Returns the string with each "\n" appearing as a new line (correct). I have the same string in my MySQL database, and am using these functions to retrieve it: function db_query($qstring,$print=0) { global $db_link; return @mysql_query($qstring); } function db_result($qhandle,$row,$field) { return @mysql_result($qhandle,$row,$field); } function GetSetting($strName) { $sql = "SELECT `Value` FROM `setting` WHERE `Status` = 'Open' AND `Name` = '".addslashes($strName)."'"; $result=db_query($sql); if (!$result) { trigger_error('DB ERROR - Error getting setting: '.db_error(), E_USER_ERROR); return false; } return db_result($result,0,'Value'); } echo GetSetting('EmailFooter'); This returns the string with the line breaks appearing as "\n" ------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n There's no "addslashes()" function or anything like that.. just some simple functions to retrieve data from the database. So why are my line breaks not showing as link breaks? Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/ Share on other sites More sharing options...
rhodesa Posted June 30, 2009 Share Posted June 30, 2009 First, where is the code that inserted the data into the table? Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866672 Share on other sites More sharing options...
Nightshade123 Posted June 30, 2009 Author Share Posted June 30, 2009 I inserted it manually with SQLyog software Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866730 Share on other sites More sharing options...
rhodesa Posted June 30, 2009 Share Posted June 30, 2009 in SQLyog, did you physically type out the slash and "n"? because it probably doesn't convert those to new lines. on that note, you can always convert it afterward with PHP, but the best way is to insert it with the PHP MySQL functions so the new lines are actually in there Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866764 Share on other sites More sharing options...
Nightshade123 Posted June 30, 2009 Author Share Posted June 30, 2009 Yes, I physically wrote in "/n", and somehow this is being preserved as text. I didn't think you could put line breaks into a MySQL table? Anyone, I created a workaround. In PHP I used: $NonHTMLEmailFooter = str_replace("/n"," ",GetSetting('HTMLEmailFooter')); Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866774 Share on other sites More sharing options...
rhodesa Posted July 1, 2009 Share Posted July 1, 2009 If you were to do an insert via the mysql functions like so: <?php $value = "------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n"; $sql = "INSERT INTO `setting` (`Name`,`Value`,`Status`) VALUES ('Test','".mysql_real_escape_string($value)."','Open')"; mysql_query($sql) or die(mysql_error()); ?> it should store it as an actual new line character and not a \n Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866841 Share on other sites More sharing options...
bshultz Posted July 1, 2009 Share Posted July 1, 2009 You would need to convert the string into an external variable that you pass into the mysql insert. Placing it in directly as text through a database tool (such as phpMyAdmin) will treat it as a string and not parse the individual line breaks. Brian http://www.mvispy.com New Developer API Released Link to comment https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-867068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.