Geo877 Posted May 7, 2008 Share Posted May 7, 2008 Hey kinda complicated problem... Basically I'm intergrating my site with phpbb3 so i'm grabbing the post text data from the mysql database, all the text comes through fine but theres one small problem - if i post a message saying line1 line2 line3 the page would display it as line1 line2 line3 . The post_text field is mediumtext and heres how i'm reading it - $postCount=0; $forum_name=$news_forum_name; $forum_id; dbConnect("phpbb3"); $sql = "SELECT * FROM `phpbb_forums` WHERE `forum_name` = '$forum_name'"; if (!mysql_query($sql)){ error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact [email protected].'); }else{ $result = mysql_query($sql); } $forum_id = mysql_result($result,0,'forum_id'); $sql = "SELECT COUNT(*) FROM `phpbb_posts` WHERE `forum_id` = '$forum_id'"; $result = mysql_query($sql); $postCount = mysql_result($result, 0); $sql = "SELECT * FROM `phpbb_posts` WHERE `forum_id` = '$forum_id'"; if (!mysql_query($sql)){ error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact [email protected].'); }else{ $result = mysql_query($sql); } $loadCount=0; for($i=($postCount-1);$i>=0;$i--){ if($loadCount<$maxNews){ $loadCount++; ${'post_subject'.$i} = mysql_result($result,$i,'post_subject'); ${'post_text'.$i} = mysql_result($result,$i,'post_text'); // add fix the simily path $targetstring = "{SMILIES_PATH}"; if(stristr(${'post_text'.$i}, $targetstring) == TRUE) { ${'post_text'.$i} = str_replace($targetstring, $phpbb_root_path."images/smilies", ${'post_text'.$i}); } echo("<h3><b>".${'post_subject'.$i}."</b></h3>"); echo("<div class='content'><p>".${'post_text'.$i}."</p></div>"); echo("<div class='meta'></div>"); } } thanks, sorry for the messy code i'm sorta new Link to comment https://forums.phpfreaks.com/topic/104580-php-isnt-reading-new-lines-from-database/ Share on other sites More sharing options...
moselkady Posted May 7, 2008 Share Posted May 7, 2008 Try to convert new-line to '< br>': ${'post_text'.$i} = nl2br(mysql_result($result,$i,'post_text')); Link to comment https://forums.phpfreaks.com/topic/104580-php-isnt-reading-new-lines-from-database/#findComment-535334 Share on other sites More sharing options...
Geo877 Posted May 7, 2008 Author Share Posted May 7, 2008 Wooo thanks moselkady, you're a saint! Link to comment https://forums.phpfreaks.com/topic/104580-php-isnt-reading-new-lines-from-database/#findComment-535357 Share on other sites More sharing options...
revraz Posted May 7, 2008 Share Posted May 7, 2008 nl2br ? Link to comment https://forums.phpfreaks.com/topic/104580-php-isnt-reading-new-lines-from-database/#findComment-535395 Share on other sites More sharing options...
skyer2000 Posted May 7, 2008 Share Posted May 7, 2008 nl2br ? http://us2.php.net/manual/en/function.nl2br.php I came here to ask the same question, thanks for the answer! Link to comment https://forums.phpfreaks.com/topic/104580-php-isnt-reading-new-lines-from-database/#findComment-535402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.