Jump to content

When inserting allot of text into a record breaks are not showing


son.of.the.morning

Recommended Posts

invoking the class

$values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted");
$fields = array('title,','img,','post,','aurthor_id,','category_id,','date_posted'); 
$obj= new DatabaseInsert;
$obj->DatabaseConnectionRequire();
$obj->ArticleInsert($values,$fields,$table); 

 

The Insert Class

class DatabaseInsert {

	function DatabaseConnectionRequire() {
		include("../scrips/php/database.connection.class.php");
		include("../scrips/php/database.settings.php");	
		include("../scrips/php/database.connection.class.invoke.php");	

	}

	function ArticleInsert($values,$fields,$table) {

		$values_imploded = implode("   ",$values);
		$fields_imploded = implode("   ",$fields);
		$i = "INSERT INTO $table ($fields_imploded) VALUES ($values_imploded)";
		//mysql_query($i) or die (mysql_error());
		//Uncomment ^ this to check the query for errors.

		if (!(mysql_query($i))) {

	    	echo "Sorry, something whent wrong there...";
		}

		else {
			echo "<strong><p style='color:green;'>Content added sucessfully!!!</p></strong>";
		}

	}
}

 

The View point

if(isset($_GET['id'])) {
// Get the id and select it's corresponding record 
$id = $_GET['id']; 
$query = "SELECT * FROM blog_posts  INNER JOIN post_categories ON blog_posts.category_id=post_categories.id WHERE blog_posts.id = $id";
$get_results = mysql_query($query) or die (mysql_error());
$results = mysql_fetch_array($get_results);
}

<?php echo $results['post']; ?> // the main body of the article

 

Well... Let's start again.

 

"Am adding text with paragraphs into my database" - what is the source of you code? Somebody add info at your page? If "yes" - what do you use for it: textarea or any other object? You didn't show it in your code.

I use a text area. When i check the post inside my database it shows paragraphs but when i try echo that record column out it doesn't show the paragraphs it just shows one big chunk of text. 

 

          	<div id="ArticleBody" style="font-size:13px; font-size: 13px; margin-top: 26px; width: 729px;">
                          <?php echo bbcode($results['post']); ?>
               </div>

Winstons's solution is correct, of course. But in order to you know - you don't have to use this function nl2br() in 2 cases:

//if you show this text again in textarea, maybe in any form, for editing
echo '<textares>'.$results['post'].'</textarea>';

// or as I said earlier - you just send it to browser with PRE tags and browser show it correctly
echo '<pre>'.$results['post'].'</pre>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.