artisticre Posted October 26, 2007 Share Posted October 26, 2007 Below is my code. When I run this, the data for $row[coach] is one long parahraph unless I enter <br> or <p></p> in the database itself. Is there a way to breakup the paragraphs at run time instead of putting it in the database for each entry? $db = mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx",$db); $result = mysql_query("SELECT * FROM coaching where (title = '$TitleList')",$db); if ($row = mysql_fetch_array($result)) { do { echo (" <table border=0 width=75% align=center> <tr> <td class=coachtitle>$row[title]</td> </tr> <tr> <td> </td> </tr> <tr> <td class=coach>nl2br($row[coach])</td> </tr> <tr> <td class=author>$row[author]</td> </tr> <tr> <td align=center><a href=/coaching.html>Back</a></td> </tr> "); } while ($myrow = mysql_fetch_array($result)); echo ("</table>"); Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/ Share on other sites More sharing options...
DyslexicDog Posted October 26, 2007 Share Posted October 26, 2007 Change: <td class=coach>nl2br($row[coach])</td> To This: <td class=coach>nl2p($row[coach])</td> Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-378712 Share on other sites More sharing options...
artisticre Posted October 26, 2007 Author Share Posted October 26, 2007 This is the outcome of this: nl2p(With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! ) What am I doing wrong? This is what I used <td class=coach>nl2p($row[coach])</td> Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-378719 Share on other sites More sharing options...
JJohnsenDK Posted October 26, 2007 Share Posted October 26, 2007 try with explode("," $row[coach]) and then use <br> in html... Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-378742 Share on other sites More sharing options...
DyslexicDog Posted October 26, 2007 Share Posted October 26, 2007 This is the outcome of this: nl2p(With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! ) What am I doing wrong? This is what I used <td class=coach>nl2p($row[coach])</td> Sorry about that didn't realize that was a custom function here's the code for that function. # function nl2p($text) { return "<p>" . str_replace(" ", "</p> <p>", $text) . "</p>"; } code was found here http://snipplr.com/view/987/nl2p/ Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-378746 Share on other sites More sharing options...
artisticre Posted October 26, 2007 Author Share Posted October 26, 2007 OK I made the changes but it isn't working. The data is inputted into the database via web panel like below and I need it to be presented this way when viewing ************************************************************************************************* this is what it is doing nl2p(With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! ) This is what I need it to look like ************************************************************************************************ With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-378755 Share on other sites More sharing options...
DyslexicDog Posted November 2, 2007 Share Posted November 2, 2007 OK I made the changes but it isn't working. The data is inputted into the database via web panel like below and I need it to be presented this way when viewing ************************************************************************************************* this is what it is doing nl2p(With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! ) This is what I need it to look like ************************************************************************************************ With whom can you share your joys and sorrows? Whom can you phone without having a reason? We have a range of emotions and sharing them doubles the good emotions and cuts the bad ones in half. Emotions always get better, therefore, through sharing. Identify the handful of people you can share your feelings with and put them on speed dial! Still Broken? can you show the code you're using if you still need help on this? Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-383774 Share on other sites More sharing options...
roopurt18 Posted November 2, 2007 Share Posted November 2, 2007 This is why poorly formatted code is dangerous. <?php echo (" <table border=0 width=75% align=center> <tr> <td class=coachtitle>$row[title]</td> </tr> <tr> <td> </td> </tr> <tr> <td class=coach>nl2br($row[coach])</td> </tr> <tr> <td class=author>$row[author]</td> </tr> <tr> <td align=center><a href=/coaching.html>Back[/url]</td> </tr> "); ?> You are calling nl2br INSIDE A STRING. You can't call a function inside a string. Your first hint was having nl2p( in the output. Quote Link to comment https://forums.phpfreaks.com/topic/74902-line-spaces-in-mysql-php/#findComment-383777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.