Jump to content

Archived

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

essjay_d12

PHP doesnt display same as MySQL

Recommended Posts

I am pulling content out of a database using the same command in PHP as MySQL.

This is the following code entered into, F_REVIEW varchar (10000), field.......

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
'Hot-shot photographer L. B. Jeffries - or "Jeff", as he's known to his chums - is at a bit of a loose end. You see he's stuck in a wheelchair, having broken a leg in a car accident whilst working on a Grand Prix circuit (perhaps a bit of a touchy subject considering Grace Kelly's in the cast). So, passing the time in the only way he can think of, he's started spying on the neighbours through his big ol' telephoto lens.

The trouble is, Jeff's hobby becomes more like an obsession when he starts to suspect the silver-haired bloke across the street (Raymond 'Perry Mason' Burr) of murdering his wife. Is his idle mind playing tricks on him, or is poor Mrs Thorwald really buried underneath the family flowerbed?'
[/quote]

// Then main thing here is that it has been split into 2 paragraphs....

Now, using the following command in MySQL 'Select F_REVIEW from films WHERE ID_NO=2;' it produces it in two paragraphs but using the same command in php produces it in one paragraph only.

The data was inserted using an insert form through php using a <textarea name="F_Review"></textarea> tag.

the following code is the php code used to get the film review.

[code]
<?php

//open connection
$conn = mysql_connect("localhost", "admin", "adm1n");
mysql_select_db("project",$conn);

$query =("SELECT F_REVIEW FROM films WHERE ID_NO=2");


$result = mysql_query($query);


while ($row = mysql_fetch_assoc($result)) {
   echo $row['F_REVIEW'];
}
?>
[/code]

How can I get php to recognise or produce it in two paragraphs?

Thanks

D

Share this post


Link to post
Share on other sites
[!--quoteo(post=354476:date=Mar 13 2006, 07:38 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 13 2006, 07:38 AM) [snapback]354476[/snapback][/div][div class=\'quotemain\'][!--quotec--]
How can I get php to recognise or produce it in two paragraphs?

Thanks

D
[/quote]

just remember that when you echo something in PHP, you're actually producing markup, and thus, you have to create recognizable line breaks (ie, <br /> tags). so, check out the nl2br() function that translates the newline characters in a code block into <br /> tags.

try this:
[code]
echo nl2br($row['F_REVIEW']);
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=354476:date=Mar 13 2006, 07:38 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 13 2006, 07:38 AM) [snapback]354476[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The data was inserted using an insert form through php using a <textarea name="F_Review"></textarea> tag.

How can I get php to recognise or produce it in two paragraphs?
[/quote]

HTML will ignore \n (linefeed) ... So you need to convert those to <br /> .. Try using nl2br() before displaying the info from the database.

Or, it may be possible that when you stored the data that was submitted, something you did stripped the line feeds.. Can't tell that unless you post that part of the code.

Share this post


Link to post
Share on other sites
echo str_replace("\n",'<Br>',$row['F_REVIEW']);

use that instead of

echo $row['F_REVIEW'];
that will replace all occurances of \n (which is new line/return charactor) with <br>

Share this post


Link to post
Share on other sites

×

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.