2

displaying html problem with php & mysql

Hi basically i have a quick mysql_fetch_array script to display the contents from the db like below:

$sql_select_jobs = $db->query("SELECT * FROM `probid_jobs`");
while ($jobs_found = $db->fetch_array($sql_select_jobs)) {
$template_output .= "<div class=\"listed-jobs\" style=\"border: 1px solid gray; border-bottom: 0px; padding: 20px;\">"; 
$template_output .= "Job Title: " . $jobs_found['job_title'] . "<br />"; 
$template_output .= "Location: " . $jobs_found['location'] . "<br />"; 
$template_output .= "Salary: " . $jobs_found['salary'] . "<br />"; 
$template_output .= "Date Posted: " . $jobs_found['date'] . "<br /><br />"; 
$template_output .= "Description: " . $jobs_found['description'] . "...<a href=\"\">more</a><br />"; 

$template_output .= "</div>";
} 

however the output would look like this:

Job Title: fff
Location: ff
Salary: fff
Date Posted: 18/06/10
Description: <b>fffffffffff <i>fffffffffffffffffff</i><br></b>...more

as you can see the description html from the db isn't getting formatted as html, for some reason it is getting escaped.

1
  • Is your fetch_array method overwriting anything in your $db class? Commented Jun 21, 2010 at 9:11

1 Answer 1

6

Change the line:

$template_output .= "Description: " . $jobs_found['description'] . "...<a href=\"\">more</a><br />"; 

with:

$template_output .= "Description: " . html_entity_decode($jobs_found['description']) . "...<a href=\"\">more</a><br />"; 

More Info:

http://www.php.net/manual/en/function.html-entity-decode.php

Sign up to request clarification or add additional context in comments.

2 Comments

thankyou that worked perfectly :), could i ask you why u think it was escaping the characters, does mysql_fetch_array not like outputting html?
@user371999: That is because at the time of insertion of records in database, the html was escaped with their corresponding entities eg $lt; for < and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.