954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

No line breaks when retrieving data from MYSQL

Thi si probably a really simple thing to solve but I am failry new to PHP and cannot find the answer anywhere.

I have a search results page that calls data from a MYSQL database. All of the correct information is displaying but one of the fields contains text on different rows.

When the PHP displays the results all of the line breaks are removed. Is there a way of stopping this?

The current code I am using is:
<?php echo $row_jobdetails['job_description']; ?>

Thanks

haribo83
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 
<?php echo "\n".$row_jobdetails['job_description']; ?>
rajarajan07
Nearly a Posting Virtuoso
1,447 posts since May 2008
Reputation Points: 167
Solved Threads: 239
 
<?php echo "\n".$row_jobdetails['job_description']; ?>


Thank you for the quick reply - unfortunately the text is still all on the same line.

haribo83
Newbie Poster
16 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

What is the content reside in the description? you mean the text from the description is all having no link breaks? do you post your code?

rajarajan07
Nearly a Posting Virtuoso
1,447 posts since May 2008
Reputation Points: 167
Solved Threads: 239
 

You could always concantenate "
" to your 'job_description' field within the SQL statement. like this...

SELECT 
        job_id, 
        job_title, 
        job_description + '' AS job_description
FROM tblTableName


...this way when your job_description field is displayed it will automatically break to the next line.

OR

<?php echo $row_jobdetails['job_description']; ?>
bhartman21
Light Poster
39 posts since May 2010
Reputation Points: 12
Solved Threads: 7
 

I'm not really a php man so the syntax may not be quite correct, but I think you're maybe looking for something like this...

<?php echo str_replace("\n","",$row_jobdetails['job_description']); ?>
mikev2
Newbie Poster
24 posts since Oct 2009
Reputation Points: 12
Solved Threads: 7
 

while($row_jobdetails = mysql_fetch_array($result)) {

echo $row_jobdetails['job_description'];
echo "
";
}

muaazab
Newbie Poster
15 posts since Apr 2008
Reputation Points: 10
Solved Threads: 2
 

but the line spaces as you would in phpMyAdmin

echo nl2br($row_jobdetails['job_description']);
liamfriel
Junior Poster
103 posts since Oct 2009
Reputation Points: 13
Solved Threads: 13
 

The answer above is how I do it. The function nl2br() was created specifically for this sort of thing.

drjohn
Posting Pro in Training
448 posts since Mar 2010
Reputation Points: 76
Solved Threads: 80
 

Hello,
Try using the nl2br(); function. It should help if I interpreted your question right. nl2br(); replaces newlines with
tags.

nl2br($variable);
Chosen13
Light Poster
38 posts since Nov 2009
Reputation Points: 10
Solved Threads: 6
 
jnmvj
lkjgblknmjb,ljhv
,mjhnv


but it wont do text formatting

nishchal_619
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: