Jump to content


Photo

PHP doesnt display same as MySQL


  • Please log in to reply
4 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 13 March 2006 - 12:38 PM

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.

<?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'];
}
?>

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

Thanks

D

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 13 March 2006 - 01:34 PM

[!--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) View Post[/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:
echo nl2br($row['F_REVIEW']);

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 13 March 2006 - 01:34 PM

[!--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) View Post[/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.
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 13 March 2006 - 01:35 PM

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>
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 13 March 2006 - 01:47 PM

echo nl2br($row['F_REVIEW']);

That worked, thank you very much

Cheers

D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users