navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Free FrontPage Templates

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

PHP/mySQL help needed [solved]

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> PHP/mySQL help needed [solved]
Page: [1]
 
Tailslide

 

Posts: 6295
Joined: 5/10/2005
From: Out here on the raggedy edge
Status: offline

 
PHP/mySQL help needed [solved] - 10/27/2005 6:27:42   
(oooh - scary! I'm not often found in the rarified atmosphere of this forum so be nice to me!!)

I'm trying to get to grips with PHP/mySQL to create a news archive for a client. I've got it all working nicely including an on-line form for them to add a new story.

My problem is that when the news items are displayed the line breaks aren't preserved. I've checked the actual DB itself in PHPAdmin and the line breaks are there - they just don't show up when the story is called.

I've been adding various different bits of code to try to keep the line breaks where they should be but nothing seems to make any difference. I'd appreciate any suggestions you might have to help.

The PHP on the page which reproduces the news stories is:

<?php

    $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("mydatabase");
 			
    // get the id from the URL request
    $id = $_REQUEST['id'];

    // retrieve the row from the database
    $query = "SELECT * FROM archive WHERE id='$id'";
   
    $result = mysql_query( $query );

    // print out the results
    if( $result && $newsitem = mysql_fetch_object( $result ) )
    {
      // print out the info
      $newsdate = $newsitem -> newsdate;
      $newssummary = $newsitem -> newssummary;
      $newstext = $newsitem -> newstext;

      echo '<p>' . $newsdate . '<br />' . '<strong>' . 
			$newssummary . '</strong>' . '<br />' . $newstext . '</p>';
			}
			
			// special characters
			$newssummary = htmlspecialchars($newssummary);
			$newstext = htmlspecialchars($newstext);
      			
			// hyperlinks
			$newstext = eregi_replace (
			 '\\[L]([-_./a-z0-9!&%#?+,\'=:;@~]+)\\[EL]',
			 '<a href="\\1">\\2</a>', $newstext);

                       // added this bit in to create line breaks
                      function br2nl($str) {
                      $str = preg_replace("/(\r\n|\n|\r)/", "", $str);
                      return preg_replace("=<br */?>=i", "\n", $str);
                      }

?>





Edit: Finally figured it out: used
$newstext = nl2br($newstext); 
and it works nicely now.

< Message edited by Tailslide -- 10/27/2005 9:11:23 >


_____________________________

"My strategy is so simple an idiot could have devised it"
Little Blue Plane Web Design | Blood, Sweat & Rust - A Land Rover restoration project
Page:   [1]

All Forums >> Web Development >> ASP and Database >> PHP/mySQL help needed [solved]
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts