On my website I have some images that are stored in the same SQL-cell as the rest of the content. When I load the page containing the images and PHP echoes the ‘article’-cell, the images are automatically enclosed in paragraph-tags, which is not what I want. Is there any way to prevent this? I’m not exactly sure wether it’s a browser-side or a server-side issue, but it appears in botch Chrome and FF.
SQL-cell ‘article’:
<img src="http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg"><p>Lorem ipsum</p>
PHP Code:
if ($pageType == 'article') {
if($pageExists==1) {
try {
$db = new PDO('pdoinfo');
} catch(PDOException $e) {echo $e->getMessage();}
$sql = $db->query("SELECT * FROM articles WHERE id=$pageName");
$result = $sql->fetchAll(PDO::FETCH_OBJ);
echo ('<div class="article"><h3>');
echo $result[0]->title;
echo('</h3><p>');
echo $result[0]->article;
echo('<span class="article-data">Geplaatst op <span class="article-date">');
echo date('d-m-Y', strtotime($result[0]->postdate));
echo ('</span> door <span class="article-author">');
echo $result[0]->author;
echo ('</span><span class="article-broadcast"><span class="st_twitter_hcount" displayText="Tweet"></span><span class="st_facebook_hcount" displayText="Facebook"></span>');
echo ('</span></span></div>');
}
else {
include('pages/404.php');
}
}
Output HTML:
[...]<p><img src="http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg"><p>Lorem ipsum</p>[...]
I just code everything myself, so no CMS involved.
When I enclose the image with p-tags myself, a redundant empty p-tag get’s inserted before the paragraph.
You have an opening
<p>on this lineecho('</h3><p>');that never closes so i suspect your seeing that.There is also no need for all thos echos’s