Link to home
Start Free TrialLog in
Avatar of jkeagle13
jkeagle13

asked on

PHP Code to Fetch Variables from MySQL & Retain Formatting

Hello,

I am trying to build a website that will allow a search to be conducted of various comments that were made. It will be for internal use only. I am using PHP. It will search by name and then return the comments the user made.

I need it to retain the exact formatting as entered. Inside the MySQL database there are line breaks, etc.

I am writing the PHP to output it to screen. It destroys all of the formatting, however, and just concatenates it all into a large lump. I must have the formatting retained. It is fine in the MySQL database so getting it on screen shouldn't be too hard.

My code looks like:

while ($row= mysql_fetch_array($result))
{      
echo "<p><b>Comments:</b><br>" .$row['Quarter3Eval']. "</b></p>";
}


If the comment initially were:

This is line A.
This is line B.
This is line C.

It smashes it together and outputs: "This is line A. This is line B. This is line C."

How can I get the output to the screen without that loss of format?

Thank you,
Joseph Irvine
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

please try this:
while ($row= mysql_fetch_array($result)) 
{      
  echo "<b>Comments:</b><br>" . str_replace($row['Quarter3Eval'], "\n", "<br/>\n") . "</b>";
}

Open in new window

Avatar of jkeagle13
jkeagle13

ASKER

Hello,

It is not throwing an error, however, nor is it displaying anything. Now it just shows up blank under comments.

Is there some additional line of code needed?

Thanks,
Joseph
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello!

Thanks! You are definitely a lifesaver! I had spent almost an hour looking for how to do that online. I am a PHP newbie who, unfortunately, had a major project due that required extensive PHP.

I do appreciate your help last-minute!

Thanks!
Joseph