user1882264
user1882264

Reputation: 21

How to extract text from MySQL database with carriage returns?

I have given input into database from textarea by MySQL.In that textarea i had typed carriage return few times. Whenever i am trying to extract that data from database, a simple line is shown how can i get the data or text as i given input with the carriage returns?

$query2 = new Bin_Query();
        $sql2="select * from `product_table` where product_id='".$_GET['product_id']."'";
        if($query2->executeQuery($sql2))
            $product_records = $query2->records;

$output['product_details']=$product_records[0]['product_details'];

that's how i retrieved the data.

Upvotes: 1

Views: 1525

Answers (1)

Tony Stark
Tony Stark

Reputation: 8094

You have to use nl2br(), check out this about more http://php.net/manual/en/function.nl2br.php actually, the correct way to use nl2br() is not to use it at all when you store your data - it's when you read from the database and are about to output it to the client. Data should not be formatted when inserted to the database, what if you later on want to create a REST-service and you really needed those newlines instead of a HTML-element? May be this help you.

Upvotes: 1

Related Questions